Tutorial: Setting Up Node.js on an Amazon EC2 Instance
A common scenario for using Node.js with the SDK for JavaScript is to set up and run a Node.js web application on an Amazon Elastic Compute Cloud (Amazon EC2) instance. In this tutorial, you will create a Linux instance, connect to it using SSH, and then install Node.js to run on that instance.
Prerequisites
This tutorial assumes that you have already launched a Linux instance with a public DNS name that is reachable from the Internet and to which you are able to connect using SSH. For more information, see Step 1: Launch an Instance in the Amazon EC2 User Guide for Linux Instances.
You must also have configured your security group to allow SSH
(port 22), HTTP
(port 80), and HTTPS
(port 443) connections. For more information about these prerequisites, see Setting Up with Amazon EC2 in the Amazon EC2 User Guide for Linux Instances.
Procedure
The following procedure helps you install Node.js on an Amazon Linux instance. You can use this server to host a Node.js web application.
To set up Node.js on your Linux instance
Connect to your Linux instance using SSH.
Install node version manager (nvm) by typing the following at the command line.
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash
We will use nvm to install Node.js because nvm can install multiple versions of Node.js and allow you to switch between them.
Activate nvm by typing the following at the command line.
. ~/.nvm/nvm.sh
Use nvm to install the version of Node.js you intend to use by typing the following at the command line.
nvm install 4.4.5
Installing Node.js also installs the Node Package Manager (npm) so you can install additional modules as needed.
Test that Node.js is installed and running correctly by typing the following at the command line.
node -e "console.log('Running Node.js ' + process.version)"
This should display the following message that confirms the installed version of Node.js running.
Running Node.js v4.4.5
Creating an Amazon Machine Image
After you install Node.js on an Amazon EC2 instance, you can create an Amazon Machine Image (AMI) from that instance. Creating an AMI makes it easy to provision multiple Amazon EC2 instances with the same Node.js installation. For more information about creating an AMI from an existing instance, see Creating an Amazon EBS-Backed Linux AMI in the Amazon EC2 User Guide for Linux Instances.
Related Resources
For more information about the commands and software used in this topic, see the following web pages:
node version manager (nvm): see nvm repo on GitHub.
node package manager (npm): see npm website.
'컴퓨터 > Amazon AWS' 카테고리의 다른 글
Install composer on Amazon AMI running on EC2 (0) | 2018.03.20 |
---|---|
AWS EC2 에 S3 마운트 하기 (0) | 2017.08.31 |
AWS EC2 기본 APM 인스톨 (0) | 2017.07.07 |
AWS EC2 sar 설치 (0) | 2017.01.24 |
AWS EC2 시간대(Timezone) 변경 (0) | 2016.05.13 |