Created
June 8, 2018 15:53
-
-
Save eoo/ce0fdc8b99a7858c76e0eadf805469e5 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
var express = require('express'); | |
var app = express(); | |
app.set('view engine', 'ejs'); | |
var bodyParser = require('body-parser'); | |
app.use(bodyParser.urlencoded({extended:true})); | |
var Person = require('./Person.js'); | |
app.use( express.static('/public') ); | |
//app.all('/', (req, res) => res.redirect('/public/personform.html') ); | |
app.use('/create', (req, res) => { | |
var newPerson = new Person({ | |
name : req.body.name, | |
age: req.body.age, | |
}); | |
newPerson.save( (err) => { | |
if (err) { | |
res.type('html').status(500); | |
res.send( 'Error: ' + err); | |
} | |
else{ | |
res.render('created', {person, newPerson}); | |
} | |
}); | |
}); | |
app.listen(3000, () => console.log('listening on port 3000 lulz')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment