javascript - Emoji's cause Express server to crash -


i trying create post emoji express endpoint:

curl --data '{"x": 10, "y":10, "z":10, "message": "😋", "usertoken": "marine"}' --header "content-type:application/json" localhost:3000/api/messages 

for reason crashes server:

syntaxerror: unexpected token     @ object.parse (native)     @ parse (/users/user/documents/uncovery/node_modules/body-parser/lib/types/json.js:84:17)     @ /users/user/documents/uncovery/node_modules/body-parser/lib/read.js:102:18     @ incomingmessage.onend (/users/user/documents/uncovery/node_modules/body-parser/node_modules/raw-body/index.js:149:7)     @ incomingmessage.g (events.js:199:16)     @ incomingmessage.emit (events.js:104:17)     @ _stream_readable.js:908:16     @ process._tickcallback (node.js:355:11) 

i went router , put console.log's in /messages endpoint see being received when express crashes result of sending emoji console.log never activated.

router.js

var models = require('../db/models.js'); var util = require('../core/utilities.js'); var sockets = require('../routes/sockets.js');  module.exports = function(router) {   //input: {x: float, y: float, z: float, message: string, usertoken: string}   router.post('/messages', function(req, res) {     console.log("emoji: ", req.body);     models.createmessage(req.body).then(       util.resolvepost.bind(this, req, res),       util.rejectpost.bind(this, req, res)       );   }); } 

i suspect has middleware , not related routes, when google emojis crash node js can't find relevant. why happening?

index.js

var http = require('http'); var morgan = require('morgan'); var express = require('express'); var socketio = require('socket.io'); var bodyparser = require('body-parser');  var util = require('./server/core/utilities.js'); var router = require('./server/routes/router.js'); var sockets = require('./server/routes/sockets.js');  var app = express(); var server = http.server(app);  app.use(morgan('combined', util.getlogstream())); app.use(bodyparser.urlencoded({ extended: false })); app.use(bodyparser.json({ limit: '50mb' })); app.use('/api', router); app.use(express.static(__dirname + '/server/landing'));  var io = socketio(server); sockets.initialize(io);  server.listen(3000, function () {   var host = server.address().address;   var port = server.address().port;   console.log('uncovery listening @ http://%s:%s', host, port); }); 


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -