Created
December 11, 2019 19:52
-
-
Save paulobunga/015217a406d14bbf5d9d4257d6d6cd2b to your computer and use it in GitHub Desktop.
Main script
This file contains hidden or 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
const express = require('express'); | |
const mongoose = require('mongoose'); | |
const bodyParser = require('body-parser'); | |
const app = express(); | |
const PORT = process.env.PORT || 3000; | |
const productCtrl = require('./product_controller'); | |
app.use(bodyParser.json()); | |
app.use(bodyParser.urlencoded({ extended: false })); | |
mongoose.connect('mongodb://localhost:27017', { | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
useFindAndModify: true, | |
}); | |
app.get('/products', productCtrl.getProducts); | |
app.get('/products/:productId', productCtrl.getProduct); | |
app.post('/products/new', productCtrl.addProduct); | |
app.patch('/products/:productId', productCtrl.updateProduct); | |
app.delete('/products/:productId', productCtrl.deleteProduct); | |
app.listen(PORT, () => | |
console.log(`Product manager API is running on PORT ${PORT}`) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment