Skip to content

Instantly share code, notes, and snippets.

@peerax
Created April 4, 2015 09:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peerax/7f59f05802c11b5ef538 to your computer and use it in GitHub Desktop.
Save peerax/7f59f05802c11b5ef538 to your computer and use it in GitHub Desktop.
nodejs+express+ejs .html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<% include ../partials/head %>
<title></title>
</head>
<body>
<%= title.date %>
</body>
</html>
var express = require('express');
var path = require('path');
var mongoose = require('mongoose');
var app = express();
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
mongoose.connect('mongodb://localhost/running');
var Event = mongoose.model('runevents', { name: String });
/*
var kitty = new Event({ name: 'Zildjian' });
kitty.save(function (err) {
if (err) // ...
console.log('meow');
});
*/
app.get('/', function(req, res){
res.send('hello world');
});
app.get('/eee', function(req, res){
Event.find({ 'date': 2007 }, function (err, result) {
if (err) return handleError(err);
console.log(result[0].name);
res.render('index', { title: result[0]});
})
});
// For redirect to 404
app.use(function(req, res) {
var err = new Error('Not Found');
err.status = 404;
res.sendFile(path.join(__dirname+'/views/404-error.html'));
});
app.listen(3000);
console.log('Server running at http://127.0.0.1:3000/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment