Answer the question
In order to leave comments, you need to log in
How to write the response of a post request to a variable?
I use the axios library on node js
I send a post request, I want to write the answer to a variable and use it outside the request, but I get Promise { <pending> }
How to get the answer and write it to a variable?
const createProduct = api.post('products', newProduct).then(function (response) {
return response.data;
});
console.log(createProduct); //Promise { <pending> }
Answer the question
In order to leave comments, you need to log in
Read about async in javascript, promises and async/await.
This question is asked on the Toaster several times a day.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question