반응형
Node.js 와 Express 로 프로젝트를 만들어보겠습니다.
기본적으로 Node.js 및 npm 등등의 기초적인 프로그램은 다른 사이트 및 블로그에서 많이 설명되어있고, 충분히 아시리라 생각하고 생략하도록 하겠습니다.
D:\_project\nodejs>npm install express-generator -g
먼저 npm 을 이용해 express-generator 을 전역으로 설치합니다.
그런 다음 express MyProject 를 해 주면 알아서 기본틀까지 쫙쫙 뽑아줍니다.
D:\_project\nodejs>express MyProject
warning: the default view engine will not be jade in future releases
warning: use `--view=jade' or `--help' for additional options
create : MyProject\
create : MyProject\public\
create : MyProject\public\javascripts\
create : MyProject\public\images\
create : MyProject\public\stylesheets\
create : MyProject\public\stylesheets\style.css
create : MyProject\routes\
create : MyProject\routes\index.js
create : MyProject\routes\users.js
create : MyProject\views\
create : MyProject\views\error.jade
create : MyProject\views\index.jade
create : MyProject\views\layout.jade
create : MyProject\app.js
create : MyProject\package.json
create : MyProject\bin\
create : MyProject\bin\www
change directory:
> cd MyProject
install dependencies:
> npm install
run the app:
> SET DEBUG=myproject:* & npm start
D:\_project\nodejs>
저의 경우에는 Atom 에디터를 사용하는데 이를 이용해서 만들어진 폴더를 열어보겠습니다.
네 이쁘게 만들어져 있는 모습을 확인하실 수 있습니다.
그렇다면 서버를 한 번 실행해볼까용~
> npm start
헐.. 아래와 같은 에러를 만나보실 수 있습니다. 왜일까요?
module.js:549 throw err; ^ Error: Cannot find module 'http-errors' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at [stdin]:3:19 at ContextifyScript.Script.runInThisContext (vm.js:50:33) at Object.runInThisContext (vm.js:139:38) at Object.<anonymous> ([stdin]-wrapper:6:22) at Module._compile (module.js:652:30) at evalScript (bootstrap_node.js:466:27)
[Finished in 1.129s]
네 그렇습니다. cmd창에서 npm install 을 실행하도록 합시다.
D:\_project\nodejs\MyProject>npm install
npm WARN deprecated jade@1.11.0: Jade has been renamed to pug, please install the latest version o
f pug instead of jade
npm WARN deprecated constantinople@3.0.2: Please update to at least constantinople 3.1.1
npm WARN deprecated transformers@2.1.0: Deprecated, use jstransformer
npm notice created a lockfile as package-lock.json. You should commit this file.
added 101 packages from 150 contributors and audited 192 packages in 6.814s
found 2 low severity vulnerabilities
run `npm audit fix` to fix them, or `npm audit` for details
자~ 이제 다시 서버를 실행해봅시다.
별도의 포트를 지정하지 않으면 3000으로 지정되니 웹브라우저를 열어서 localhost:3000 으로 확인을 해봅시다.
정말 간단하쥬?
반응형
'Programming > Node.js' 카테고리의 다른 글
[Handlebars.js] Template와 Helper 사용하기 (0) | 2019.07.06 |
---|---|
node.js dotenv 로 환경변수 관리하기 (0) | 2018.10.03 |
Node.js 노드 내장 모듈 cryoto (1) | 2018.10.01 |
Node.js + Express + Handlebars 프로젝트 생성하기 (0) | 2018.08.17 |
Node.js 및 npm 설치 (0) | 2018.08.13 |