如何退出node命令或者node server
答案:1 悬赏:0 手机版
解决时间 2021-01-23 20:17
- 提问者网友:暮烟疏雨之际
- 2021-01-23 14:07
如何退出node命令或者node server
最佳答案
- 五星知识达人网友:从此江山别
- 2021-01-23 15:37
如果是要退出node命令的话,可以使用:Selection_076
Js代码 收藏代码
$ node
> 9+23
32
> process.exit()
$
或者
Js代码 收藏代码
$ node
> 9+23
32
> .exit
$
如果是要退出node server的话,可以使用:Selection_077
Selection_080
别人是推荐点击两下 Ctrl-C, 但是我使用的时候不好使,不知道是不是因为需要大写的C才行,所以我使用 Ctrl-Shift-C 的时候就可以了,不过这个快捷键需要结合下面的代码使用:
Js代码 收藏代码
// this function is called when you want the server to die gracefully
// i.e. wait for existing connections
var gracefulShutdown = function() {
console.log("Received kill signal, shutting down gracefully.");
server.close(function() {
console.log("Closed out remaining connections.");
process.exit()
});
// if after
setTimeout(function() {
console.error("Could not close connections in time, forcefully shutting down");
process.exit()
}, 10*1000);
}
// listen for TERM signal .e.g. kill
process.on ('SIGTERM', gracefulShutdown);
// listen for INT signal e.g. Ctrl-C
process.on ('SIGINT', gracefulShutdown);
全部的代码为:
Js代码 收藏代码
var express = require('express');
var app = express();
// listen on the specified port
var server = app.listen(8080);
// serve out content
app.get('/', function(req, res){
var body = 'Hello World';
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Content-Length', body.length);
res.end(body);
});
// this function is called when you want the server to die gracefully
// i.e. wait for existing connections
var gracefulShutdown = function() {
console.log("Received kill signal, shutting down gracefully.");
server.close(function() {
console.log("Closed out remaining connections.");
process.exit()
});
// if after
setTimeout(function() {
console.error("Could not close connections in time, forcefully shutting down");
process.exit()
}, 10*1000);
}
// listen for TERM signal .e.g. kill
process.on ('SIGTERM', gracefulShutdown);
// listen for INT signal e.g. Ctrl-C
process.on ('SIGINT', gracefulShutdown);
因为点击Ctrl-Shift-C之后就会触发process函数。
或者使用:Selection_081
Ctrl-z 之后,使用
C代码 收藏代码
ps aux | grep node
kill -9 PID
Js代码 收藏代码
$ node
> 9+23
32
> process.exit()
$
或者
Js代码 收藏代码
$ node
> 9+23
32
> .exit
$
如果是要退出node server的话,可以使用:Selection_077
Selection_080
别人是推荐点击两下 Ctrl-C, 但是我使用的时候不好使,不知道是不是因为需要大写的C才行,所以我使用 Ctrl-Shift-C 的时候就可以了,不过这个快捷键需要结合下面的代码使用:
Js代码 收藏代码
// this function is called when you want the server to die gracefully
// i.e. wait for existing connections
var gracefulShutdown = function() {
console.log("Received kill signal, shutting down gracefully.");
server.close(function() {
console.log("Closed out remaining connections.");
process.exit()
});
// if after
setTimeout(function() {
console.error("Could not close connections in time, forcefully shutting down");
process.exit()
}, 10*1000);
}
// listen for TERM signal .e.g. kill
process.on ('SIGTERM', gracefulShutdown);
// listen for INT signal e.g. Ctrl-C
process.on ('SIGINT', gracefulShutdown);
全部的代码为:
Js代码 收藏代码
var express = require('express');
var app = express();
// listen on the specified port
var server = app.listen(8080);
// serve out content
app.get('/', function(req, res){
var body = 'Hello World';
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Content-Length', body.length);
res.end(body);
});
// this function is called when you want the server to die gracefully
// i.e. wait for existing connections
var gracefulShutdown = function() {
console.log("Received kill signal, shutting down gracefully.");
server.close(function() {
console.log("Closed out remaining connections.");
process.exit()
});
// if after
setTimeout(function() {
console.error("Could not close connections in time, forcefully shutting down");
process.exit()
}, 10*1000);
}
// listen for TERM signal .e.g. kill
process.on ('SIGTERM', gracefulShutdown);
// listen for INT signal e.g. Ctrl-C
process.on ('SIGINT', gracefulShutdown);
因为点击Ctrl-Shift-C之后就会触发process函数。
或者使用:Selection_081
Ctrl-z 之后,使用
C代码 收藏代码
ps aux | grep node
kill -9 PID
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯