1. NodeJS 설치
Ubuntu 20.04에서 NodeJS 기본 설치 시 12.x 올드 버전이므로, 최신 버전 설치 위해 별도로 저장소 설정 스크립트를 다운로드한 후 패키지 목록을 업데이트하여 설치를 수행해야 합니다.
curl -sL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install nodejs
sudo apt install build-essential
node --version // 설치된 NodeJS 버전 확인
2. Express-generate 이용한 프로젝트 생성
2.1 Express-generater 설치
npm install express-generator -g // 설치
express --version // 설치 확인
2.2 Express-generater 프로젝트 생성
express hello-express // express {폴더명} 으로 폴더 및 프로젝트 생성 됨
cd hello-express // 생성된 폴더로 이동
npm install // 의존성 패키지 설치
npm start // 프로젝트 실행
http://localhost:3000 // 웹페이지 접속
3. Express-generate 이용한 프로젝트 구성
라우팅 app.method( PATH , HANDLER ) 구조
var app = express();
app.get('/', function (req, res) {
res.send('Hello World!');
});
// accept POST request on the homepage
app.post('/', function (req, res) {
res.send('POST 요청');
});
// accept PUT request at /user
app.put('/user', function (req, res) {
res.send('PUT 요청');
});
// accept DELETE request at /user
app.delete('/user', function (req, res) {
res.send('DELETE 요청');
});
'코딩' 카테고리의 다른 글
NodeJS Express + MariaDB 개발 환경 구성 (0) | 2025.06.03 |
---|---|
VS Code 원격 작업 설정 (0) | 2025.06.03 |