0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

How to construct Node.js Express web page on AWS EC2 linux instance

Last updated at Posted at 2020-05-11

Introduction

This document is a weak memorandum for my cheap working job

connect AWS EC2 instnce

connect by SSH to Linux instance from ec2-user

  • push [Connect (接続) ] buttom below
スクリーンショット 2020-05-12 0.22.29.png

use EC2 Instance Connect (browser base SSH conection)

  • select EC2 Instance Connect and push [Connect (接続) ] buttom below
スクリーンショット 2020-05-12 0.23.20.png

install Node.js

install nvm (node version manager)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

activate nvm

. ~/.nvm/nvm.sh

install recent version of Node.js

nvm install node

test for correct Node.js install and execute

node -e "console.log('Running Node.js ' + process.version)"

then display below on terminal

Running Node.js VERSION

install Express web framework for Node.js

make service directory and change this directory

mkdir dev/nodejs/express/app
cd dev/nodejs/express/app

Node.js project initialization

npm init -y

install Node.js web framework Express

npm install --save express

then create node_modules folder and setting lock file package-lock.json

install Express-Generator that create web application template library for express framework

install Express-Generator and create a template

npm install -g express-generator

create web application template that name is members

express --view=ejs members 

move directory for web application template and install

cd members
npm install

test running express web application

npm start

then display terminal blow

> members@0.0.0 start /home/ec2-user/dev/nodejs/express/app/members
> node ./bin/www

open inbound port 3000 on AWS EC2 security group

  • click security group link anchor
スクリーンショット 2020-05-12 21.46.01.png
  • then click [edit inbound rule (インバウンドルールの編集)] button
  • add rule below
type(タイプ) port area(ポート範囲) source(ソース)
custom TCP 3000 0.0.0.0/0
スクリーンショット 2020-05-12 21.21.24.png

access web browser to URL

http://public DNS:3000/

  • public DNS is about
    • ec2-xx-xxx-xxx-xx.ap-northeast-1.compute.amazonaws.com

then display web browser blow

スクリーンショット 2020-05-12 21.22.23.png
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?