admin管理员组文章数量:1356826
Iam new to Node JS when i make any changes to the node file it is not updating in the server and also when i change the port number and kill the server and start it again it is not working
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello');
}).listen(8080);
Iam new to Node JS when i make any changes to the node file it is not updating in the server and also when i change the port number and kill the server and start it again it is not working
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello');
}).listen(8080);
Share
Improve this question
asked May 23, 2020 at 13:41
user11640506user11640506
972 silver badges9 bronze badges
1
- "when i make any changes to the node file it is not updating in the server" What do you mean by that? If you mean you're expecting it to change immediately, it won't. The code is read into memory and executed from memory; if you change the code file, you have to stop Node.js and start ig again. "when i change the port number and kill the server and start it again it is not working" That will definitely work, I think you must have forgotten to stop it or something like that. – T.J. Crowder Commented May 23, 2020 at 13:44
3 Answers
Reset to default 5I have found a quick solution to fix this thing. You have to install a node module called as nodemon. This module helps to automatically restart your Server once you made the changes in Source code.
npm install -g nodemon
And nodemon will be installed globally to your system path.
You can also install nodemon as a development dependency:
npm install --save-dev nodemon
By default, node does not automatically restart when there are any changes in the file. You might want to try the package nodemon, which can watch for file changes and auto restart the server.
You can try adding an host name to your listen function
let http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
本文标签: javascriptNode JS server not reflecting changes in server fileStack Overflow
版权声明:本文标题:javascript - Node JS server not reflecting changes in server file - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744060101a2583971.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论