JavaScript

NodeJs에서 프로젝트 생성하는 순서

우롱차 2020. 9. 16. 20:45
728x90

Nodejs를 사용하여 Web Application Server 생성하기

1. workspace / nodejs 폴더 생성

 

2. nodejs 폴더에서 express 프레임워크를 사용하여 프로젝트 생성

   - express Hello_Node

 

3. cd Hello_Node : 프로젝트 폴더로 이동

 

4. npm install : dependency download

   - package.json 파일에 설정된 dependency들을 download 하여 node_modules 폴더에 저장

 

5. 프로젝트 시작

   가. npm start : 기본 시작하기

   나. nodemon : 개발환경에서 파일이 변경(수정)하면 자동으로 서버를 재시작하는 tool을 사용하기


nodejs의 view 설정

1. nodejs의 탄생시점에서는 jade라는 view를 사용했다.

 

2. 2.x로 버전업이 되면서 이름이 pug로 변경되었다.

 

3. npm install pug : view단의 도구 설치

 

4. views 폴더의 파일들 \*.pug로 확장자 변경

 

5. app.js 파일에서 jade를 pug로 변경

 

>> Hello_Node/README.md


이렇게 해주면 views 폴더에서 jade가 아니라

pug로 프로젝트가 생성돼서 간편!

 

 

express --view=pug 프로젝트명

 ex) express --view=pug Node_bbs

 

cd 프로젝트 폴더

 ex) cd Node_bbs      // 프로젝트 이름 찾을때는 웬만하면 tab키를 이용해 자동완성 해주기

 

dependency를 복사해서 전부 update를 시켜준다.

 

-- npm install로 하는 방식

npm install cookie-parser

npm install debug

npm install express

npm install http-errors

npm install morgan

npm install pug

npm install mongoose

npm install // 위에는 예시 꼭 마지막에는 해줘야하는 명령어

학원에서는 npm으로 일단 사용중

 

yarn add moment // 날짜 관련된 친구

 

~이 ^로바뀜

^는 최신버전이라는 소리

더보기

yarn add cookie-parser 
yarn add debug 
yarn add express 
yarn add http-errors 
yarn add morgan 
yarn add pug // npm이 조금 느린것을 개선하기 위해 yarn이라는 새로운 tool
yarn add mongoose 

yarn add moment // 날짜 관련된 친구
yarn // 위에는 예시 꼭 마지막에는 해줘야하는 명령어


express Node_Todo

cd Node_Todo

npm install

npm install pug

npm install express

npm uninstall jade

app.js의 view engine 을 jade에서 pug로 변경

 

yarn 의 삭제명령어는 remove

 

728x90