Created
May 15, 2015 03:05
-
-
Save nelreina/ed731447d670316058c7 to your computer and use it in GitHub Desktop.
Express simple server with handelbars as view engine
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
/** | |
* Created by nelsonreina on 5/13/15. | |
*/ | |
function showView(request, response){ | |
var data = {title:"My Awesome Title", message:"Hello Handlebars"}; | |
response.render('home', data); | |
} | |
function getToppings(request, response){ | |
var data = ['peperoni', 'cheese', 'sausage']; | |
response.status(200); | |
response.set('Content-Type', 'application/json'); | |
response.send(data); | |
} | |
var express = require('express'); | |
var hb = require('express-handlebars'); | |
var http = require('http'); | |
var bodyParser = require('body-parser'); | |
var port = process.env.PORT || 3000; | |
var app = express(); | |
app.use(bodyParser.urlencoded({extended:true})); | |
app.use(bodyParser.json()); | |
app.use(express.static(__dirname + '/public')); | |
app.engine('handlebars', hb()); | |
app.set('view engine', 'handlebars'); | |
app.get('/' , showView); | |
app.get('/api/toppings' , getToppings); | |
var server = http.createServer(app); | |
server.listen(port); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment