- Print
- PDF
Node.js
- Print
- PDF
Available in Classic
Node.js is a Javascript development stack service platform utilizing Node.js while using Linux as an OS. It is automatically configured on NAVER Cloud Platform's Compute infrastructure service and can be instantly put into service through a configuration process with only a few steps.
The advantages of using Node.js are as follows:
- You can reliably use the Node.js development stack service utilizing the infrastructure services of NAVER Cloud Platform.
- You can select a server image and specifications to automatically install and use the Node.js server.
For more information on the software used in NAVER Cloud Platform's Node.js, see the following websites:
Creating and accessing server
The method for creating and accessing the server is the same as creating a regular server on NAVER Cloud Platform. The following are detailed procedures and reference guides:
Procedure | Description |
---|---|
1. Set ACG |
|
2. Create server |
|
3. Set public IP |
|
4. Set port forwarding |
|
5. Get admin password |
|
6. Access server |
|
- After you access and log in to the server, change the password of the root account to one you can remember. Enter the
passwd root
command to set a new password. - If you can't connect to the Node.js Web service even if there is no problem in the public IP address and ACG, your web server process might be stopped. Run the restart command (
systemctl start httpd
) on the terminal program to restart the process.
Using server
When the server is created, Node.js Development Package is installed for easy use.
The provided open source is Node Version Manager (NVM), and the installation directory of the Node.js file is /root/nodejs
and /root/.nvm
.
While connected to the server, you can run the following commands:
- Check the downloadable nvm remote versions:
nvm list-remote
- Install the nvm version you want:
nvm install v(버전)
- Check the currently active nvm version:
nvm current
- Check the installed nvm version:
nvm ls
- Set nvm alias:
nvm alias default v(버전)
- Change the nvm version to be used (when installing multiple versions):
nvm use v(버전)
- Install the Express module using npm:
npm install -p --save express
- Install the PM2 module using npm:
npm install -g --save pm2
- Check nvm help:
nvm --help
Examples of utilizing Express modules
Describes examples of creating Express modules and utilizing them to the web server.
After you access the server, enter the
vi hello.js
command to open the editor.Press the [I] key to open the input mode, and then enter the file properties as follows:
var express = require('express'); var app = express(); app.get('/', function (req, res) { res.send('Hello Express Server!'); }); app.listen(3000, function () { console.log('Express App Server : Listening on port 3000!'); });
Press the [Esc] key to close the input mode, and then enter
:wq
to close the vi editor.NoteIf you change the Node version, you need to install the Express and PM2 modules with NPM. Use the following commands:
- Check the currently active nvm version:
nvm current
- Set the nvm version to be used:
nvm use v(버전)
- Install the Express module:
npm install -p --save express
- Install the PM2 module:
npm install -g --save pm2
- Check the currently active nvm version:
Run the created Express module file.
root@ndjs-ub:~# node hello.js Express App Server : Listening on port 3000!
To allow TCP 3000 port for browser access, set the ACG on the console.
- For more information about setting ACG, see ACG.
Enter the following commands in the terminal connected to the server.
- You can view the Express web server execution result.
curl http://(public IP address):3000 ... Hello Express Server!
PM2 utilization monitoring
You can monitor the Node applications utilizing the PM2 module.
The following describes how to run the PM2 module using the hello.js example file.
root@ndjs-ub:~# pm2 start -f hello.js
...
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting /root/hello.js in fork_mode (1 instance)
[PM2] Done.
┌─────┬──────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼──────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ hello │ default │ N/A │ fork │ 5085 │ 0s │ 0 │ online │ 0% │ 27.3mb │ root │ disabled │
└─────┴──────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘