- cmd 실행
npm install pm2 -g
pm2 명령어
pm2 start node/main.js// main.js 실행
pm2 monit// 현재 pm2에 의해 실행되고 있는 프로그램을 볼 수 있음
pm2 list// 현재 실행중인 프로세스의 리스트를 볼 수 있음
pm2 stop name// 프로그램을 끌 수 있음
pm2 kill// pm2로 커진 프로세스들을 다 꺼 버림
pm2 start node/main.js --watch// 소스 코드를 수정하면 자동으로 껐다킴
pm2 log// 문제점이 있을 때 화면에 보여줌
pm2 start node/main.js --watch --no-daemon// 백그라운드 실행이 아님
pm2 start node/main.js --watch --ignore-watch="data/*" --no-daemon
npm 사이트
Node Package Manager, 노드 패키지 매너저
npm init//package.json을 만드는 명령어결과
This utility will walk you through creating a package.json file. It only covers the most common items, and tries to guess sensible defaults. See `npm help init` for definitive documentation on these fields and exactly what they do. Use `npm install <pkg>` afterwards to install a package and save it as a dependency in the package.json file.Press ^C at any time to quit. package name: (desktop) // 패키지의 이름 version: (1.0.0) // 패키지의 버전 description: // 프로젝트 설명 입력 entry point: (index.js) // 자바스크리브 실행 파일 진입점 test command: // 엔터 키 클릭 git repository: // 코드를 저장해둔 Git 저장소 주소를 의미 keywords: // 엔터키 클릭 author: // 이름 입력 license: (ISC) // 엔터 키 클릭 About to write to C:\Users\ssjjn\OneDrive\Desktop\package.json:{ "name": "desktop", "version": "1.0.0", "description": "", "main": "index.js", "directories": { "lib": "lib" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" }Is this OK? (yes)
package.json 파일 // 설치한 패키지의 버전을 관리하는 파일
{
"name": "node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
콘솔에서 입력
npm install-S sanitize-html결과
added 15 packages, and audited 16 packages in 4s 9 packages are looking for funding run `npm fund` for details found 0 vulnerabilities
{
"name": "node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"lib": "lib"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
"dependencies": {
"sanitize-html": "^2.11.0"
}
}
dependecies라는 속성이 새로 생겼고, sanitize-html 라는 이름과 함계 설치된 버전이 저장됨.
추가로 node_modules라는 폴더도 생성됨. 그 안에 설치한 패키지들이 들어 있음.
분명히 sanitize-html 하나만 설치했는데 패키지가 여러 개 들어 있다. 이는 sanitize-html 이 의존하는 패키지들이다. 패키지 하나가 다른 여러 패키지에 의존하고, 그 패키지들은 또 다른 패키지들에 의존함. 이렇게 의존 관계가 복잡하게 얽혀 있어 package.json이 필요한 것