初始化一个node项目

初始化一个nodejs项目

1
2
# cd到目录,初始化
npm init

安装依赖

1
2
npm install express
npm install --save-dev nodemon

package.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{
"name": "soap-demo",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node index.js",
"dev": "nodemon index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^5.0.0-beta.2"
},
"devDependencies": {
"nodemon": "^3.1.0"
}
}

index.js

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const express = require('express')
const app = express()

let notes = [

]

app.get('/', (request, response) => {
response.send('<h1>Hello World!</h1>')
})

app.get('/api/notes', (request, response) => {
response.json(notes)
})

const PORT = 3001
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`)
})
作者

Wei Mo

发布于

2019-09-16

更新于

2024-03-21

许可协议

评论