Skip to content

Instantly share code, notes, and snippets.

@Raduuu
Created Jun 9, 2020
Embed
What would you like to do?
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