Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl with nodejs express - POST data

I'm trying to simulate a POST request to a server app based in Express for nodeJS. It's running on localhost:3000 (JS Fiddle: http://jsfiddle.net/63SC7/)

I use the following CURL line:

 curl -X POST -d "{\"name\": \"Jack\", \"text\": \"HULLO\"}" -H "Content-Type: application/json" http://localhost:3000/api 

but get the error message:

Cannot read property 'text' of undefined

Any ideas what I'm doing wrong?

Note: I can make a successful GET request using this line:

curl http://localhost:3000/api

like image 252
user3281031 Avatar asked Mar 21 '23 09:03

user3281031


1 Answers

Assuming you're trying req.body.text,

Have you used bodyParser?

app.use(express.bodyParser());
like image 152
josh3736 Avatar answered Mar 22 '23 23:03

josh3736