<aside> 🧑🏻 AWS에 초점을 맞춘 강의가 아니기 때문에 EC2, RDS, ELB에 대한 디테일한 설명은 생략할 예정이다. 혹시 AWS에 대한 기본기를 다지고 싶다면 아래 강의를 추천한다.
비전공자도 이해할 수 있는 AWS 입문/실전 (https://inf.run/73afg)
</aside>
<aside> 🧑🏻🏫
참고) 이번 실습에서는 Node 기반의 Express 서버를 활용하지만, 이후 실습에서는 Spring Boot를 활용해 테스트를 할 예정이다.
</aside>
Node 설치
Ubuntu 환경에서 Express 서버를 실행시키려면 Node.js가 설치되어 있어야 한다. 그래서 Ubuntu에 우선 Node.js를 설치해보자.
https://github.com/nodesource/distributions
$ sudo su
$ apt-get update && /
apt-get install -y ca-certificates curl gnupg && /
mkdir -p /etc/apt/keyrings && /
curl -fsSL <https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key> | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && /
NODE_MAJOR=20 && /
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] <https://deb.nodesource.com/node_$NODE_MAJOR.x> nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list && /
apt-get update && /
apt-get install nodejs -y
# 잘 설치됐는 지 확인하기
$ node -v
Express 서버 셋팅하기
기본 프로젝트 셋팅
$ mkdir my-server
$ cd my-server
$ npm init # 의존성 관리 파일 생성
$ npm i express # express 라이브러리 설치
API 로직 작성
app.js
const express = require('express');
const app = express();
const port = 80;
app.get('/boards', (req, res) => {
res.send([
{ id: 1, title: '첫 번째 게시글', content: '이것은 첫 번째 게시글의 내용입니다.' },
{ id: 2, title: '두 번째 게시글', content: '이것은 두 번째 게시글의 내용입니다.' },
{ id: 3, title: '세 번째 게시글', content: '이것은 세 번째 게시글의 내용입니다.' }
]);
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})
pm2 설치하기
Node 기반의 서버는 pm2
를 활용해서 많이 실행시킨다. 서비스를 운영하는 데 있어서 유용한 기능들을 pm2
가 많이 가지고 있기 때문이다.
$ npm i -g pm2
API 서버 실행시키기
$ pm2 start app.js
잘 잘동하는 지 확인하기