Created
November 22, 2017 01:39
-
-
Save thegrid22593/810cb448ba9b20ea14192f51a5da3524 to your computer and use it in GitHub Desktop.
Basic Express API Routing
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
const express = require('express'); | |
const router = express.Router(); | |
const db = require('./../db/db.js'); | |
router.get('/projects', (req, res) => { | |
console.log('you hit projects'); | |
Project.find(function (err, projects) { | |
if(!err) { | |
console.log(projects); | |
res.json(projects); | |
} else { | |
console.log(err); | |
} | |
}); | |
}); | |
router.post('/projects', (req, res) => { | |
console.log(req.body); | |
var project = new Project({ | |
name: req.body.name, | |
description: req.body.description, | |
technologies: req.body.technologies | |
}); | |
project.save((err) => { | |
if(err) console.log(err); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment