Skip to content

Instantly share code, notes, and snippets.

@WitkowskiMichau
Created April 25, 2021 20:14
Show Gist options
  • Save WitkowskiMichau/4530e466c41e7894a49883cf98d33b24 to your computer and use it in GitHub Desktop.
Save WitkowskiMichau/4530e466c41e7894a49883cf98d33b24 to your computer and use it in GitHub Desktop.
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const morgan = require('morgan')
const low = require('lowdb')
const FileSync = require('lowdb/adapters/FileSync')
const DB_PATH = './db.json'
const startDataServer = (mockData = false) => {
const db = low(new FileSync(DB_PATH))
const app = express()
// HTTP request logger middleware for node.js
app.use(morgan('tiny'))
// CORS is a node.js package for providing a Connect/Express middleware that can be used to enable CORS with various options.
app.use(cors())
// Parse incoming request bodies in a middleware before your handlers, available under the req.body property.
app.use(bodyParser.json())
// set headers
app.use((req, res, next) => {
res.setHeader('Cache-Control', 'no-cache')
next()
})
// future routers
// userRoutes(app, db)
app.head('/', (req, res) => res.sendStatus(200))
const PORT = 5001
console.log(`listening on port ${PORT}`)
app.listen(PORT)
}
startDataServer()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment