---
# System prepended metadata

title: nodejs 初始化專案
tags: [nodejs]

---

# 安裝套件
```
npm init -y
npm i express
npm i -D nodemon
```

## index.js
```javascript=
const express = require('express');
const app = express();
const port = 3000;

app.get('/', (req, res) => {
  res.send('hello');
});

app.listen(port, () => {
  console.log('server start');
});
```

# 修改npm script
```javascript=
scripts: {
  "dev": "nodemon index.js"
}
```

# 執行npm script
```shell=
npm run dev
```