[LINUX] [AWS] Install node.js on EC2 instance and execute sample program

environment

Windows 10 Home Tera Term 4.105 (Terminal for Mac users)

Premise

・ Amazon Linux EC2 -SSH connection is possible -Outbound HTTP connection is possible

install node.js

ec2-linux


$ cd ~
$ wget https://nodejs.org/dist/v12.18.2/node-v12.18.2-linux-x64.tar.xz

Get the latest version link from Official Site image.png

node-v12.18.2-linux-x64.tar.xz

ec2-linux


$ cd ~
$ wget https://nodejs.org/dist/v12.18.2/node-v12.18.2-linux-x64.tar.xz

Make sure you have a tar file

ec2-linux


$ ls
$ node-v12.18.2-linux-x64.tar

Since the extension is xz, convert it to tar

ec2-linux


$ mv node-v12.18.2-linux-x64.tar.xz node-v12.18.2-linux-x64.tar

Defrost

ec2-linux


$ tar xvf node-v12.18.2-linux-x64.tar

Decompression is completed when various outputs are output and stopped image.png

Set the path to node-v12.18.2-linux-x64 / bin where the execution command is installed and move

ec2-linux


$ export PATH=$PATH:~/node-v12.18.2-linux-x64/bin
$ cd node-v12.18.2-linux-x64/bin

Prepare a sample program called app.js

app.js


const http = require('http');

const hostname = 'localhost';
const port = 8080;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World');
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Run

ec2-linux


$ touch app.js
$ vim app.js

~~~~~~Paste the sample program(Please check the vim command yourself)~~~~~~

$ node app.js
Server running at http://localhost:8080/

Recommended Posts

[AWS] Install node.js on EC2 instance and execute sample program
AWS EC2 instance launch and ssh connection
[2020 version] How to install Python3 on AWS EC2
A story about trying to install uwsgi on an EC2 instance and failing
Install the Python API of the autonomous driving simulator LGSVL and execute the sample program
Install Docker on AWS
# 2 Build a Python environment on AWS EC2 instance (ubuntu18.04)
Deployment procedure on AWS (2) Server (EC2 instance) environment settings
Execute python3 system with PHP exec () on AWS EC2
[AWS EC2] How to install Maven on Amazon Linux 2
[AWS EC2] How to install only MySQL client on Amazon Linux 2 and connect to RDS
Install AWS SDK for PHP on AWS EC2 (PHP7.2 + Apache2.4.41 + OPCashe + Composer)
Python --Install MySQLDB on EC2
Building an environment to execute python programs on AWS EC2
Sample script to monitor Load Average on CloudWatch on AWS EC2
xgboost (python) on EC2 Spot instance environment prepared by AWS Lambda
# 3 Build a Python (Django) environment on AWS EC2 instance (ubuntu18.04) part2
Create an AWS Cloud9 development environment on your Amazon EC2 instance
Quickly install OpenCV 2.4 (+ python) on OS X and try the sample
How to install pandas on EC2 (How to deal with MemoryError and PermissionError)
Install Mecab and mecab-python3 on Ubuntu 14.04
Install and run dropbox on Ubuntu 20.04
Install OpenCV and Chainer on Ubuntu
Install CUDA 8.0 and Chainer on Ubuntu 16.04
Build and install OpenCV on Windows
Use jupyter on AWS GPU instance
Install pyenv on EC2 (Amazon Linux)
Install fabric on Ubuntu and try
Install easy_install and pip on windows
Set cron from 1 on Ubuntu 16.04 (Sakura VPS) and execute python program regularly
Prepare the environment of Chainer on EC2 spot instance with AWS Lambda
# 1 Until you deploy Django's web application (instance construction with EC2 on AWS)
Install Python3 and Django on Amazon Linux (EC2) and run your web server
Change AWS EC2 instance from t2 to t3
I'll install Ruby on EC2 (Amazon Linux2) 2020
Run TensorFlow on a GPU instance on AWS
Install wsl2 and master linux on windows
Install and launch k3s on Manjaro Linux
Install and Configure TigerVNC server on Linux
Install Puppet Master and Client on Ubuntu 16.04
Install pyenv and Python 3.6.8 on Ubuntu 18.04 LTS
Install Odoo on Alibaba Cloud ECS instance
Install Python 3.8, Pip 3.8 on EC2 (Amazon Linux 2)
Install pyenv and rbenv on CentOS system-wide