cheoljun.dev

Babel, Nodemon, Express을 활용한 Node.js 프로젝트 설정 방법

Node.js
ID
63
status
Public
menu
Frontend
submenu
tags
Node.js
summary
thumbnail
babel.png
date
Jul 28, 2024
  1. 프로젝트 폴더 생성
    1. mkdir project_name
  1. 프로젝트로 이동
    1. cd project_name
  1. Node.js 프로젝트 초기화 → 프로젝트 디렉토리에 “package.json” 생성
      • package.json: 프로젝트의 메타데이터(프로젝트 이름, 버전, 설명, 주요파일, 스크립트, 의존성)를 포함 + 프로젝트를 관리
      npm init -y
  1. IDE로 프로젝트 실행
  1. package.json에서 scripts, main, keywords, author 삭제
  1. license는 원하는거 추가 ex) MIT
  1. description에는 프로젝트 설명 추가
  1. Github에 올릴 걸 고려해서 README.md 추가
  1. 필요한 패키지 설치
  1. Nodemon 설치
    1. npm i nodemon -D
  1. Babel 설치하기 전 babel.config.json 파일 생성
  1. nodemon.json 파일 생성
  1. src 폴더를 만들고 server.js 파일 생성
  1. git init .명령어 입력
  1. Babel 설치
    1. npm i @babel/core @babel/cli @babel/node @babel/preset-env -D
  1. .gitignore 생성해서 node_modules 입력
  1. nodemon 설정하기
      • nodemon.json 파일에 다음 추가
      { "exec": "babel-node src/server.js" }
  1. babel.config.json 파일에 다음 추가
    1. { "presets": ["@babel/preset-env"] }
  1. package.json에 scripts 추가
    1. "scripts": { "dev": "nodemon" }
  1. express 설치
    1. npm i express
  1. pug 설치
    1. npm i pug
  1. src/server.js에 다음 추가해서 express app 생성
    1. import express from "express"; const app = express(); app.listen(3000);
  1. npm run dev를 실행시키면 서버가 실행 됨
  1. localhost:3000 ㄱㄱ
Cheoljun Park
Fullstack Developer

구현 과정과 트러블슈팅, 배운 것들을 기록합니다.

댓글