的Node.js - 在浏览器中显示的页面推新代码
问题描述:
我有一个“世界你好”运行Ubuntu远程服务器上的微细节点的测试应用程序(Nginx的代理,PM2管理)的Node.js - 在浏览器中显示的页面推新代码
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World');
}).listen(8080, '127.0.0.1');
console.log('Server running at http://127.0.0.1:8080/');
运行正常后不会改变(本地Ubuntu的服务器上:
curl http://127.0.0.1:8080
Hello World
,并通过Web浏览器
当我更新代码:
changing to: res.end('Hello World, again');
,并通过SCP推:
scp -v -i ~/.ssh/id_rsa.pub -r hello.js [email protected]:/home/myself
hello.js有效地修改在远程服务器上,但正在运行的应用程序节点是hello.js仍显示先前的文字...
什么我是否想让新代码运行?
感谢反馈
答
您需要重新启动应用程序,以使其使用新代码。
pm2 restart hello // or however your app's name is
上传新文件后应该做的伎俩。
还有一个option在文件更改时自动重启您的应用程序。为此,开始您的应用程序与
pm2 start hello.js --watch
非常感谢...我忘了 - 观看,现在正在更新,重新启动并显示新的文本! – erwin