Node.js
    • PDF

    Node.js

    • PDF

    Article Summary

    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.
    Note

    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:

    ProcedureDescription
    1. Set ACG
    • Reference guide: ACG
    • Must set the following ports:
      • TCP 22 port for a terminal connection
      • TCP 3000 port for the use of web server (can be changed)
    2. Create server
    • Reference guide: Create server
    • Image type Application, Application image type Node.js
    3. Set public IP
    4. Set port forwarding
    5. Get admin password
    6. Access server
    Note
    • 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.

    1. After you access the server, enter the vi hello.js command to open the editor.

    2. 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!');
      });
      
    3. Press the [Esc] key to close the input mode, and then enter :wq to close the vi editor.

      Note

      If 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
    4. Run the created Express module file.

      root@ndjs-ub:~# node hello.js
      Express App Server : Listening on port 3000!
      
    5. To allow TCP 3000 port for browser access, set the ACG on the console.

      • For more information about setting ACG, see ACG.
    6. 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 │
    └─────┴──────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
    

    Was this article helpful?

    What's Next
    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.