#Server Strting module
This module can be used without abstracting by require()
method.
When this module is installed, the code uses -g
option. -g
makes the installing globally.
Then the modules which are installed with -g
option are placed in {prefix}/lib/node_modules
and the executable files are placed in {prefix}/bin
We will install supervisor
and forever
modules with the option like this.
1 | npm install -g supervisor |
#supervisor moduleNode.js
programming makes us stop and restart the server
again and again whenever we need to change the code because though the files are changed, the script executing doesn’t get impact. But, supervisor
module recognizes the difference and restarts the server
automatically.
we can check their document here -> https://github.com/petruisfan/node-supervisor
supervisor
module’s basic usage is supervisor (file name)
.
We will see what happens with the module from now on.
I made a code for showing the changing. When I made this code,1
2
3
4
5
6
7
8var http = require("http");
http.createServer(function ( request, response){
response.writeHead(200, {'Content-Type':'text/html'});
response.end('<h1>Supervisor test - 1</h1>');
}).listen(52273, function(){
console.log("Server Running at http://127.0.0.1:52273");
});
I see the page when I enter http://127.0.0.1:52273
or localhost:52273
And I change and save the server
code file like this without restarting,1
2
3
4
5
6
7
8var http = require("http");
http.createServer(function ( request, response){
response.writeHead(200, {'Content-Type':'text/html'});
response.end('<h1>Supervisor test - 2</h1>');
}).listen(52273, function(){
console.log("Server Running at http://127.0.0.1:52273");
});
and then refresh the web page, the page is changed like this.
supervisor
module restarts any programs when the code ends no matter what the programs are. This means in the case we run some short code like1
console.log("Run with supervisor");
the program gets infinite restarting.
so we should use the module when we start server program.