1. npm init

먼저 새로운 폴더를 열고

npm init 을 해주고 초기 세팅을 마치면 package.json 이 생기게된다.

{
  "name": "packaqge-study1",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \\"Error: no test specified\\" && exit 1",
    "start": "node index.js" // npm start 를 하면 자동으로 실행되는 쉘 스크립트이다.
  },
  "author": "shipjh",
  "license": "ISC",
}

2. npm 외부 모듈 사용해보기

randomcolor

위의 랜덤한 컬러를 리턴해주는 누군가 만들어둔 모듈을 사용할 예정이다.

터미널에 npm i randomcolor 를 입력해주면 자동으로 다운로드가 된다 ( i 는 install의 약자 )

다운로드가 완료되면 node_modules 아래 패키지가 하나 생긴다.

그리고,

package-lock.json 이 생기고, package.json의 내용중 dependencies 가 추가 되어있는 것을 볼 수 있다.

// package.json
{
  "name": "packaqge-study1",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \\"Error: no test specified\\" && exit 1",
    "start": "node index.js"
  },
  "author": "shipjh",
  "license": "ISC",
  **"dependencies": {
    "randomcolor": "^0.6.2"  
  }**
}

package.json 에 dependencies 가 생기게되고

“^” 표시와 함께 버전도 나오게된다 여기서 웃음표시(^)는 해당 버전보다 위 버전이다 라는 말을 나타낸다.