I'm trying to test a message I am sending from a client through faye.
curl -X POST -H "Content-Type:application/json" -d '{"message":"Hi there."}' http://localhost:8000/message
This is the culript line.
TypeError: Cannot read property 'message' of undefined<br>
UPDATE: The culript might actually be here...
app.post('/message', function(req, res) {
bayeux.getClient().publish('/channel', {text: req.body.message});
res.send(200);
});
Unfortunately, I get this error. For some reason, it sees message as an undefined property,and I'm not sure why.
Thanks in advance for your help.
You're missing the required body-parsing middleware, such as body-parser
's .json()
middleware.
Install that module and add
var bodyParser = require('body-parser');
app.use(bodyParser.json());
somewhere before your routes.