- npm은 Node Package Manager의 약어로, 이름 그대로 노드 패키지 매니저입니다.
- 서비스에 필요한 패키지를 하나씩 추가하다 보면 어느새 패키지 수가 많이지게 됨
- 이때 설치한 패키지의 버전을 관리하는 파일이 바로 package.json
- package.json을 생성하기 위한 과정은 다음처럼 명령어에 npm init 을 검색한다.
- npm init 실행 (cmd 화면에서 진행함)
$ 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 json` 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: (폴더명) [프로젝트 이름 입력]
version: (1.0.0) [프로젝트 버전 입력]
description: [프로젝트 설명 입력]
entry point: index.js
test command: [엔터 키 클릭]
git repository: [엔터 키 클릭]
keywords: [엔터 키 클릭]
author: [여러분의 이름 입력]
license: (ISC) [엔터 키 클릭]
About to write to C:\\Users\\zerocho\\npmtest\\package.json:
{
"name": "npmtest",
"version": "0.0.1",
"description": "hello package.json",
"main": "index.js",
"scripts": {
"test": "echo \\"Error: no test specified\\" && exit 1"
},
"author": "ZeroCho",
"license": "ISC"
}
Is this ok? (yes) yes
• package name: 패키지의 이름입니다. package.json의 name 속성에 저장됩니다.
• version: 패키지의 버전입니다. npm의 버전은 다소 엄격하게 관리됩니다.
• entry point: 자바스크립트 실행 파일 진입점입니다.
보통 마지막으로 module.exports를 하는 파일을 지정합니다. package.json의 main 속성에 저장됩니다.
• test command: 코드를 테스트할 때 입력할 명령어를 의미합니다.
package.json scripts 속성 안의 test 속성에 저장됩니다.
• git repository: 코드를 저장해둔 깃(Git) 저장소 주소를 의미합니다.
나중에 소스에 문제가 생겼을 때 사용자들이 이 저장소에 방문해 문제를 제기할 수도 있고,
코드 수정본을 올릴 수도 있습니다. package.json의 repository 속성에 저장됩니다.
• keywords: 키워드는 npm 공식 홈페이지(<https://npmjs.com>)에서 패키지를 쉽게 찾을 수 있도록 해줍니다.
package.json의 keywords 속성에 저장됩니다.
• license: 해당 패키지의 라이선스를 넣으면 됩니다.
- npm init이 되면 package.json 파일이 나오게 됨
- 아래는 package.json파일
{
"name": "zxc",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \\"Error: no test specified\\" && exit 1"
},
"author": "",
"license": "ISC"
}
NPM EXPRESS 설치
(base) glory@Gloryui-MacBookPro abc % npm install express
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
npm WARN [email protected] No repository field.
+ [email protected]
added 50 packages from 37 contributors and audited 50 packages in 2.222s
found 0 vulnerabilities
(base) glory@Gloryui-MacBookPro abc %