프로젝트 혹은 모듈을 사용하기 위해 필요한 또다른 모듈(패키지)들의 목록. package.json에 적혀있다. npm install
을 실행하면 이곳에 적혀있는 모든 패키지들이 node_modules
폴더에 생성된다.
"dependencies": {
"express": "^4.17.1"
}
package-lock.json 파일은 npm에 의해서 프로젝트의 node_modules나 package.json이 수정되는 경우 생성되거나 업데이트되며 당시 의존성에 대한 정보를 모두 가지고 있다.
해당 파일 안에는 패키지의 특정 version이 아니라 version range를 가지고 있다.(caret range)
package-lock.json
파일은 의존성 트리에 대한 정보를 모두 가지고 있습니다.
package-lock.json
파일은 저장소에 꼭 같이 커밋해야 합니다.
package-lock.json
파일은 node_modules 없이 배포하는 경우 반드시 필요합니다.
GitHub에 Commit할 때, 업로드되지 않는 파일 목록
/node_modules
개발자에게 필요한 dependencies. 그렇다면 dependencies와 devDependencies의 차이점은? dependencies는 기술스펙으로 되어야 할 라이브러리들이 명시되고, devDependencies에는 개발 시 필요한 라이브러리들이 적힌다.
런타임에도 계속 사용되면 dependencies, 프로젝트 컴파일에 필요하면 devDependencies
"dependencies": {
"express": "^4.17.1"
},
"devDependencies": {
"@babel/core": "^7.15.0",
"@babel/node": "^7.14.9",
"@babel/preset-env": "^7.15.0",
"nodemon": "^2.0.12"
}
자바스크립트 컴파일러. NodeJS가 이해하지 못하는 최신 자바스크립트 문법들을 모두가 이해할 수 있는 자바스크립트로 바꾸어준다(컴파일 해준다). 최신 트렌드의 자바스크립트를 사용하기 위해서 필요하다.
Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.
npm install --save-dev @babel/core
babel/core
패키지를 npm을 통해 설치하되, devDependencies에 저장한다.
Create babel.config.json
configuration file (특정 preset을 사용하도록 설정할 수 있다)
touch babel.config.json
npm install @babel/preset-env --save-dev
{
"presets": ["@babel/preset-env"]
}
nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.
npm install --save-dev nodemon
npm install @babel/core @babel/node --save-dev
"scripts": {
"dev": "nodemon --exec babel-node index.js"
}
npm run dev
를 통해 index.js
파일을 실행하돼, babel-node
를 통해서 실행하고, nodemon을 통해 수정사항을 모니터링한다.
"scripts": {
"dev": "nodemon --exec babel-node src/server.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
},
"devDependencies": {
"@babel/core": "^7.15.0",
"@babel/node": "^7.14.9",
"@babel/preset-env": "^7.15.0",
"nodemon": "^2.0.12"
}