How to end an express.js / node POST response?

前端 未结 7 1685
情歌与酒
情歌与酒 2020-12-28 12:51

Im trying to just stop the post request after I\'ve saved a document to the DB, ie:

app.post(\'/blah\'), function(req,res){ 
//my code does a bunch of stuff
         


        
7条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 13:13

    While you can use the underlying end method borrowed from Node's http module, Express.js has its own send method that calls end when appropriate:

    /**
     * Send a response.
     *
     * Examples:
     *
     *     res.send(new Buffer('wahoo'));
     *     res.send({ some: 'json' });
     *     res.send('

    some html

    '); * res.send(404, 'Sorry, cant find that'); * res.send(404); * * @param {Mixed} body or status * @param {Mixed} body * @return {ServerResponse} * @api public */ res.send = function(body){ . . . // respond this.end(head ? null : body); return this; };

提交回复
热议问题