NodeJS_0006:nodejs响应超时处理

1,

    // 获取参数设置
    app.get('/getPara', function(req, res) {
        // console.log(req.hostname);
        // console.log(req.params);
        // console.log(req.path);
        console.log(req.query);
        // http://localhost:81/getPara?id=3&name=wg
        JSONCRUD.findOne(req.query.id, function(err, data) {
            if (err) {
                return res.json({ "error": "error" });
            }
            res.json({
                'val': data
            });
        });
        // 响应超时处理
        res.setTimeout(3000, function() {
            res.json({ "error": "error" });
        });
    });

 

posted @ 2020-07-10 11:33  琥珀君  阅读(513)  评论(0编辑  收藏  举报