Last active
February 1, 2018 06:55
-
-
Save epk/9a1da2e61da7737c8c5bfdd71d8c59cd 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(); | |
var handlebars = require('express-handlebars').create({ defaultLayout: 'main'}); | |
var bodyParse = require('body-parser'); | |
var urlencodedParser=bodyParse.urlencoded({extended:false}); | |
app.engine('handlebars',handlebars.engine); | |
app.set('view engine', 'handlebars'); | |
app.set('port', process.env.PORT || 3018); | |
app.use(express.static(__dirname + '/public')); | |
app.get('/', function(req,res){ | |
res.render('home'); | |
}); | |
app.get('/submit', function(req,res){ | |
res.render('submit'); | |
}); | |
app.get('/about', function(req,res){ | |
res.render('about'); | |
}); | |
app.use(function(req, res, next){ | |
res.status(404); | |
res.render('404'); | |
}); | |
app.use(function(err, req, res, next){ | |
console.error(err.stack); | |
res.type('text/plain'); | |
res.status(500); | |
res.render('500'); | |
}); | |
app.post('/submit', urlencodedParser , function(req , res){ | |
console.log(req.body); | |
}); | |
app.listen(app.get('port'), function(){ | |
console.log('Express started on localhost:'+app.get('port') + '; ctrl-c to terminate.'); | |
}); |
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
asdas |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment