Skip to content

Instantly share code, notes, and snippets.

@Raduuu
Created June 9, 2020 07:01
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Raduuu/1ce6aec615dd6e8bb490a7d54fb6a991 to your computer and use it in GitHub Desktop.
import express from 'express'
import mongoose from 'mongoose'
import { json, urlencoded } from 'body-parser'
import morgan from 'morgan'
import config from './config'
import cors from 'cors'
import productRouter from './resources/product/product.router'
export const app = express()
app.disable('x-powered-by')
app.use(cors())
app.use(json())
app.use(urlencoded({ extended: true }))
app.use(morgan('dev'))
app.use('/product', productRouter)
const connect = (url = options.dbUrl, opts = {}) => {
return mongoose.connect(
url,
{ ...opts, useNewUrlParser: true }
)
}
export const start = async () => {
try {
await connect()
app.listen(config.port, () => {
console.log(`REST API on http://localhost:${config.port}/api`)
})
} catch (e) {
console.error(e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment