본문 바로가기
IT/JavaScript와 Framework

nodemon 모듈 - 서버 자동 재기동 모듈

by 골든크랩 2021. 6. 16.
728x90
반응형

Node.js 는 소스 변경시 재기동해줘야 하는데, nodemon 을 사용하면 자동 재기동이 가능함. 

주로 개발에서 사용하고, 운영에서는 forever 를 주로 사용함.

개발에만 집중할 수 있도록 도와주는 패키지.

 

npm i nodemon -g ==> global 로 설치

 

npm i -d nodemon  ==> package.json 

 

 

 

Either through cloning with git or by using npm (the recommended way):

 

npm install -g nodemon

 

And nodemon will be installed globally to your system path.

You can also install nodemon as a development dependency:

 

npm install --save-dev nodemon

 

With a local installation, nodemon will not be available in your system path. Instead, the local installation of nodemon can be run by calling it from within an npm script (such as npm start) or using npx nodemon.

 

--save-dev 로 하면 개발 dependencies 에만 들어간다.

 

실행 :

=> 로컬로 설치하면 nodemon 실행시 명령어를 찾지 못한다.

이때는 npx 로 실행해야 한다. 글로벌로 설치하면 nodemon 으로 실행할 수 있다.

 

~/Projects/NodeJS/express-first$ npx nodemon app.js

 

더 나은 방법으로...package.json 파일에 아래처럼 start 부분을 추가하는 것이다.

"scripts": {

"test": "echo \"Error: no test specified\" && exit 1"

"start": "npx nodemon app.js"   <======추가된 부분

},

 

그리고 실행방법은...

npm start

 

 

 

 

728x90
반응형

댓글