Created
June 9, 2020 07:01
-
-
Save Raduuu/1ce6aec615dd6e8bb490a7d54fb6a991 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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