"Node.js is a platform built on Chrome's JavaScript runtime(V8 JavaScript Engine.V8 is Google's open source JavaScript engine.) for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices." - nodejs.org
After installing node.js as mentioned in early post, create file app.js
http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(2000,'88.208.221.72');
console.log('Server running at port 2000');
and save and exit.
Then run the following command
node app.js
And you can see the output through http://yourip:2000
Running a Node.js application this wayr will block additional commands until the application is killed by pressing CTRL+C.
Then install PM2, which is a process manager for Node.js applications. PM2 provides an easy way to manage and daemonize applications (run them as a service).
Use Node Packaged Modules (NPM), which is basically a package manager for Node modules that installs with Node.js, to install PM2. Use following command to install PM2:
npm install pm2 -g
Then use pm2 start command to run the application, app.js, in the background:
pm2 start app.js
This adds application to PM2's process list, which is outputted every time start an application:
PM2 assigns an App name (based on the filename) and a PM2 id. PM2 also maintains other information, such as the PID of the process, its current status, and memory usage.
Applications that are running under PM2 will be restarted automatically if the application crashes or is killed, but an additional step needs to be taken to get the application to launch on system startup (boot or reboot).
The startup subcommand generates and configures a startup script to launch PM2 and its managed processes on server boots. Specify the platform you are running on
pm2 startup centos
To find your os version following command can be used
cat /etc/redhat-release
After installing node.js as mentioned in early post, create file app.js
http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(2000,'88.208.221.72');
console.log('Server running at port 2000');
and save and exit.
Then run the following command
node app.js
And you can see the output through http://yourip:2000
Running a Node.js application this wayr will block additional commands until the application is killed by pressing CTRL+C.
Then install PM2, which is a process manager for Node.js applications. PM2 provides an easy way to manage and daemonize applications (run them as a service).
Use Node Packaged Modules (NPM), which is basically a package manager for Node modules that installs with Node.js, to install PM2. Use following command to install PM2:
npm install pm2 -g
Then use pm2 start command to run the application, app.js, in the background:
pm2 start app.js
This adds application to PM2's process list, which is outputted every time start an application:
PM2 assigns an App name (based on the filename) and a PM2 id. PM2 also maintains other information, such as the PID of the process, its current status, and memory usage.
Applications that are running under PM2 will be restarted automatically if the application crashes or is killed, but an additional step needs to be taken to get the application to launch on system startup (boot or reboot).
The startup subcommand generates and configures a startup script to launch PM2 and its managed processes on server boots. Specify the platform you are running on
pm2 startup centos
To find your os version following command can be used
cat /etc/redhat-release
No comments:
Post a Comment