티스토리 뷰

React

[React] package.json이란?

Xion 2020. 11. 13. 21:07

리액트를 배우다보면 package.json 이라는 파일이 있다

대체 뭐하는 파일인지 궁했는데 조금씩 알아보기로 하자 !

먼저

package.json을 보자

{
  "name": "react-hyemin",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start" : "node index.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "hyeminPark",
  "license": "ISC",
  "dependencies": {
    "express": "^4.17.1"
  }
}

안에 "start"라고 명시되어있는 건 npm run start 를 실행할 때 바로 start 부분이 저 부분과 매칭되어 실행되는 것.

즉, node가 index.js를 실행시켜주는 것이라고 생각하면 된다 !

 

index.js

const express = require('express')
const app = express()
const port = 5000

app.get('/',(req,res) => res.send('Hello World'))
app.listen(port, () => console.log(`Example ${port}! `))

get 이란 루트 directory즉 "/"부분으로 호출을하면 res로 반응하여 Hello world가 출력이 되는 부분.

해당 부분의 listen 이란, 이 app 이 5000에 listen하면 console.log가 실행되는 것이다.