#express js #api #node #node js #web services

How to get post data in json in express JS APIs - Node JS

Thought it sounds simple and straight forward, this thing killed a lot of my time at the initial time of getting into node JS.

the query string are directly available in the request for both get and post methods but to get the post data you send in json format you need to update you express JS index.js . In the root of your express JS setup you have index.js add the following line on the top after the creation of app.

app.use(express.json());

Now you will be able to access the json data in post request in req.body

If you are facing the same issue with your form submits, please follow the link for the solution.

mohammed-samgan-khan

Hi, I am Samgan, I excel at solving complex problems involving logic and step by step breakdown of the problem. Besides, to develop complex algorithms, I specialise in problem framing, systems design, and product development strategy. Sometimes I also enjoy public speaking.  

I am also the creator of penit.ink, a site which provides young writers with a free hand place to show their creation to the world. Irrespective of the niche, if you write this place is defiantly for you.