POST method not working but GET method working when using CORS Node js - node.js

I want to POST the data from body to mongodb but when i use CORS then i am not able to post the data , GET method in working. What configuration we have to make in CORS middleware

This error and resolution came up as the first result of my google query using your error message and expressjs Cannot POST / error using express

Related

Api is working fine with postman but not working in react

Nodejs api is working fine with postman but while i'm trying it with react i'm getting some errors like message: "Request aborted", name: "AxiosError", code: "ECONNABORTED"
I haven't added the authentication yet in my api so that is not needed i guess.
I tried to send it in various ways even i tried to handle preflight problem of cors but not sure if i handled that or not! the api is working with postman absolutely ok response as expected.
make sure you don't pass credentials query params in you get request. if you have added credentials in your get request replace your http method with post.

AWS lambda api gateway with node.js express returns an error of "net::ERR_CONTENT_DECODING_FAILED 200"

The error occurs when my client sends a GET request to the node.js server hosted with AWS lambda api gateway. The server is expected to send back an array of objects with res.json({}). The weird part is that when i test with a response of object or an array of objects with lesser variables in it, it works. I have also tried to JSON.stringify() the array in the server side and JSON.parse() in the client but to no avail. Thanks in advance to everyone helping me and do guide me along as its my first time posting on StackOverflow.
Edit: However i have tried it with a curl command to the endpoint and it returns the json array without any errors.
Alright everyone i found which part of my code caused the bug!
app.use(busboy());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(busboyBodyParser());
As i was playing around with file transfer before with the npm package 'Busboy', imported and used some packages associated with it. However, i forgotten to comment out these codes and thus, i believe it messed up the response body and got the error. Just to be clear this was in the node.js backend.

express-http-context npm module doesnt work with express post request

I setup a traced id in express.js . I used the module express-http-context
httpContext.set('traceId', uuid.v4())
But when I try to fetch it using httpContext.get('traceId') it doesnt seem to work and gives me undefined for POST express request.
It works fine for GET request.
Not sure what is wrong with this

code HPE_INVALID_METHOD Node js Hapi js

I am trying to make GET request to my API endpoint and when I do the request from another server to the API I see this strange error (on the API):
170125/230803.439, [log,connection,client,error] data: {"bytesParsed":0,"code":"HPE_INVALID_METHOD"}
What does this error mean?
I am sorry I did request on https:// I should have done it on http:// instead

Facebook chatbot post callback doesn't have the correct data structure in nodejs

I've implemented a webhook for a facebook chatbot with php using laravel and all works fine, when I message my bot I receive a post request with expected data structure and I manage to have all working well. Then I was trying to do the webhook implementation using nodejs but when I message my bot the post request that I receive is not the one it would be expected. This is kind of weird because I was able to validate the webhook with the token. I have used the same facebook app and page that I used for the php implementation so I don't think the problem is there. Here's the code in node: http://pastebin.com/0GQcXdV2
I would expect the request structure to be: http://pastebin.com/GFU89LjA
but instead it's this: http://pastebin.com/51S7DrkG
I'm sorry if this question seems stupid and I'm missing something obvious but can't figure out what. I'm kind of new to node js so maybe this is a newbie mistake, but if anyone can tell me what am I doing wrong it would be very appreciated. Thanks in advance
I managed to solve my problem by importing npm body-parser and make my express app use it for returning JSON. According to the npm documentation the bodyParser object provides middleware factories that expose the body of the request and assign it to req.body in plain text, json , raw or url encoding form body (https://www.npmjs.com/package/body-parser). To solve my problem i just added the following two lines of code:
var bodyParser = require('body-parser');
app.use(bodyParser.json());
More information on body parser can be found here.

Resources