npm init으로 package.json에 대한 기본설정을 할 수 있다.
kimdaeyoon ~ cd Desktop
kimdaeyoon ~/Desktop cd boiler-plate
kimdaeyoon ~/Desktop/boiler-plate 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: (boiler-plate)
version: (1.0.0)
description:
entry point: (index.js)
test command:
git repository:
keywords:
author: Viktor
license: (ISC)
About to write to /Users/kimdaeyoon/Desktop/boiler-plate/package.json:
{
"name": "boiler-plate",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Viktor",
"license": "ISC"
}
Is this OK? (yes)
index.js 파일 생성하기
npm install express
express공식문서에서 자세한 사용법을 확인할 수 있다.
const express = require('express')
//express 모듈을 가져옴
const app = express()
//새로운 express 앱을 만듬
const port = 5000
//포트는 자유롭게 사용 가능
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
package.json에서 다음과 작성
"scripts": {
"start": "node index.js",