👻

Express & Prisma【2Express 初期設定②】

2022/09/19に公開

Express & Prisma【2Express 初期設定②】

YouTube: https://youtu.be/exohvVmPly4

helmet: https://www.npmjs.com/package/helmet
morgan: https://www.npmjs.com/package/morgan
cors: https://www.npmjs.com/package/cors

npm i helmet
npm i morgan
npm i --save-dev @types/morgan
npm i cors
npm i --save-dev @types/cors
package.json
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.18.1",
    "helmet": "^6.0.0",
    "morgan": "^1.10.0"
  },
  "devDependencies": {
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.14",
    "@types/morgan": "^1.9.3",
    "ts-node-dev": "^2.0.0"
  }
index.ts
import express from 'express'
import helmet from 'helmet'
import morgan from 'morgan'
import cors from 'cors'

const app = express()
const port = 4000

app.use(express.json())
app.use(express.urlencoded({extended: true}))

app.use(cors())
app.use(helmet())
app.use(morgan('common'))

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})

Discussion