Permalink
Browse files

Add post/posts using postman. Post added to mongodb

  • Loading branch information...
Nyweron committed Jun 28, 2017
1 parent 4b17834 commit 55a6ff020c9b844ff450728b1368067910381939
Showing with 19 additions and 3 deletions.
  1. +19 −3 api/server.js
@@ -1,11 +1,27 @@
var express = require('express')
var Post = require('./models/post')
var app = express()
app.get('/', function(req, res) {
res.send('Hello Nyweron test!')
})
var port = process.env.PORT || 3000
app.listen(port, function() {
console.log('app listening on port 3000')
//use postman
app.post('/api/posts', function(req, res, next) {
console.log(req.headers.username)
var post = new Post({
username: req.headers.username,
body: req.headers.body
})
post.save(function(err, post) {
if (err) { return next(err) }
console.log("Post added")
res.send(201)
})
})
var port = process.env.PORT || 3002
app.listen(port, function() {
console.log('app listening on port', port)
})

0 comments on commit 55a6ff0

Please sign in to comment.