npm (Node Package Manager)
- 노드의 패키지 매니저
- 남의 코드를 사용하여 프로그래밍 가능
원하는 경로에 publish 폴더 생성
USER@DESKTOP-7TQNQP3 MINGW64 /c/project-jisu/node study/lecture/publish
$ npm init
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: (publish) npmtest
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author: Hebe
license: (ISC) MIT
About to write to C:\project-jisu\node study\lecture\publish\package.json:
{
"name": "npmtest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Hebe",
"license": "MIT"
}
Is this OK? (yes) yes
express 설치
$ npm i express
added 57 packages, and audited 58 packages in 989ms
7 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
cooker-parser body-parser 설치 ->버젼을 기록해야 다시 설치해도 같은 버젼이 설치된다 에러방지!
$ npm i cookie-parser body-parser
added 4 packages, changed 2 packages, and audited 62 packages in 564ms
7 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
nodemon 설치
$ npm i -D nodemon
added 32 packages, and audited 94 packages in 978ms
10 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
rimraf 설치
npm i rimraf -D
결과
- node_modukes : 용량이 많이 차지하기 때문에 배포시에는 삭제하고 개발시넌 npm i 로 재설치
- package-lock.json : 정확한 버젼을 기록
- package.json
{
"name": "npmtest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index"
},
"author": "Hebe",
"license": "MIT",
"dependencies": {
"body-parser": "^1.20.2",
"cookie-parser": "^1.4.6",
"express": "^4.18.2"
},
"devDependencies": {
"nodemon": "^2.0.20",
"rimraf": "^4.1.2"
}
}
package 안의 명령어를 사용하고 싶으면 npx로 사용 가능
npx rimraf node_modules/
'Node.js' 카테고리의 다른 글
Node)Cluster module (0) | 2023.03.01 |
---|
댓글