hyungmuk's blog

express-generator 본문

개발 & 공부/node.js

express-generator

hyungmuk 2020. 3. 11. 17:38

express-generator 설치

npm i -g express-generator

express-generator 를 설치하면 express 명령어를 사용할 수 있다.

express 명령어 사용법

터미널에 express -h를 입력하면 express 명령어 사용법이 나온다.

express -h

  Usage: express [options] [dir]

  Options:

        --version        output the version number
    -e, --ejs            add ejs engine support
        --pug            add pug engine support
        --hbs            add handlebars engine support
    -H, --hogan          add hogan.js engine support
    -v, --view <engine>  add view <engine> support (dust|ejs|hbs|hjs|jade|pug|twig|vash) (defaults to jade)
        --no-view        use static html instead of view engine
    -c, --css <engine>   add stylesheet <engine> support (less|stylus|compass|sass) (defaults to plain css)
        --git            add .gitignore
    -f, --force          force on non-empty directory
    -h, --help           output usage information

예제

express --no-view .

현재 디렉토리에 express 관련 디렉토리와 파일을 생성한다.

express --no-view .
destination is not empty, continue? [y/N] y

   create : public\
   create : public\javascripts\
   create : public\images\
   create : public\stylesheets\
   create : public\stylesheets\style.css
   create : routes\
   create : routes\index.js
   create : routes\users.js
   create : public\index.html
   create : app.js
   create : package.json
   create : bin\
   create : bin\www

   install dependencies:
     > npm install

   run the app:
     > SET DEBUG=mask-map:* & npm start

패키지들을 다운로드 하기 위해 npm install 을 실행한다.

npm install
npm notice created a lockfile as package-lock.json. You should commit this file.
added 52 packages from 36 contributors and audited 135 packages in 4.741s
found 0 vulnerabilities

다음과 같은 구조로 express 프로젝트가 생성되었다.

express 실행

npm start

> mask-map@0.0.0 start C:\00.dev\vue\mask-map
> node ./bin/www

http://localhost:3000/ 로 접속하면 index 페이지를 확인 할 수 있다.

포트 번호 바꾸기

bin폴더에서 www을 에디터로 열어서 코드를 수정하자.

기본 포트 번호가 3000으로 되어있다.

var port = normalizePort(process.env.PORT || '8000');
app.set('port', port);

8000으로 수정 후 다시 npm start를 하면 http://localhost:8000/ 으로 접속 된다.