Wednesday, June 29, 2016

Installing nodejs on EC2 SERVER

Node.js is an open-source, cross-platform runtime environment for developing server-side Web applications. Although Node.js is not a JavaScript framework, many of its basic modules are written in JavaScript, and developers can write new modules in JavaScript.


This tutorial assume that you know how to create/open  AWS EC2 instance. In case you are not aware of this, Please Click Here

  • Open new Terminal window.
  • Run nvm installer
    • ...with either curl or wget.
      • curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
      • wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
    • The script clones the nvm repository to ~/.nvm and adds the source line to your profile (~/.bash_profile, ~/.zshrc, ~/.profile, or ~/.bashrc). (You might want/need to add the source loading line by yourself, if the automated install tool does not add it for you.)
      export NVM_DIR="$HOME/.nvm"
      [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
      [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
  • If everything went well, you should now be able to reload the shell by running
    • source ~/.bashrc
    • (Another option is to open a new Terminal window/tab.)
  • Verify installation
    • To verify that nvm has been installed, do: command -v nvm
  • List what versions of Node are currently installed (probably none).
    • nvm ls
  • Install latest Node.js LTS release (recommended for production usage).
    • nvm install v8.9.4

  • Install Current Node.js release with latest features (for testing the future features of Node).
    • nvm install v9.6.1

  • 8) create a new file server.js to test node app.
               const http = require('http');
    http.createServer( (request, response) => {
      response.writeHead(200, {'Content-Type': 'text/plain'});
      response.end('Hello World\n');
    }).listen(8124);'
    console.log('Server running at http://127.0.0.1:8124/');
    save the file and run the following command. Make sure you are in the folder where script is placed
                      

                       node server.js
     9)
              Server running at http://127.0.0.1:8124/




    10)  Last and final step is to add 8124 port in allowed list of security group for the instance where nodejs is installed. for more details Click Here.

    11) open the webbrowser and open the URL http://127.0.0.1:8124/. replace 127.0.0.1 with your server's IP.

    If you can see following, grab a cup of coffee and relax. Nodejs is installed properly.













     


             




    No comments: