NodeJS By Examples
Start & Stop nodeJS
Create file index.js
var util = require('util'),
http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('Hello World23\nssssada\t adsdas 33sss <b>asd</b>');
}).listen(8080, '127.0.0.1');
console.log('Server running at http://127.0.0.1:8080/');
util.puts('> hello world running on port 8080 ');
1. Start node
#npm install -g nodemon
$nodemon index.js
Nodemon monitors folder structure for changes and after cahnge any file restarts node server.
2. Run forever
#npm install -g forever
Syntax:
forever [start | stop | stopall | list] [options] SCRIPT [script options]
$forever start index.js
Starts nodejs in the background.
STOP NODE
CTRL + c
$killall -9v node
$killall -u john -kills all processes for a given user