Skip to content

Instantly share code, notes, and snippets.

@prashanth-sams
Created March 7, 2019 15:50
Show Gist options
  • Save prashanth-sams/2df26825a16db4c758e7d0240411be62 to your computer and use it in GitHub Desktop.
Save prashanth-sams/2df26825a16db4c758e7d0240411be62 to your computer and use it in GitHub Desktop.
ServerPortRouter
const express = require('express');
const app = express();
const ServerPortRouter = express.Router();
const ServerPort = require('../models/ServerPort');
ServerPortRouter.route('/add').post(function (req, res) {
const serverport = new ServerPort(req.body);
serverport.save()
.then(serverport => {
res.json('Server added successfully');
})
.catch(err => {
res.status(400).send("unable to save to database");
});
});
ServerPortRouter.route('/').get(function (req, res) {
ServerPort.find(function (err, serverports){
if(err){
console.log(err);
}
else {
res.json(serverports);
}
});
});
module.exports = ServerPortRouter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment