Sunday, August 12, 2018

Forever plugin with NodeJS ,or Run Nodejs server continuously


Forever plugin with NodeJS urpose: A simple CLI tool for ensuring that a given node script runs continuously Wen you want to create server through node js and wants to run it continuously will server is up then you can use this plugin.
  $ [sudo] npm install forever -g
  Example code
index.js
var http = require("http");
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);
// Console will print the message
console.log('Server running at http://127.0.0.1:8081/');  

USAGE

If you want to run any program for a while then you can use this plugin .
1)Start
For running program with forever use below command
forever start index.js

NOw go to browser and type
http://127.0.0.1:8081/  
you will get result as Hello World.
2) Stop
For stopping your programme
forever stop index.js
 
3)Logs
You can also check logs
type below command
forever logs
it will give you log file path stored on your machine so you can go to that location and view file.

No comments:

Post a Comment

How to check whether operating system is 64 bit or 32bit?

What is 32 and 64 bit operating system? The terms 32-bit and 64-bit refer to the way a computer's processor that is CPU, handles info...