Skip to content

Instantly share code, notes, and snippets.

@nicksheffield
Last active January 4, 2016 18:29
Show Gist options
  • Select an option

  • Save nicksheffield/8660554 to your computer and use it in GitHub Desktop.

Select an option

Save nicksheffield/8660554 to your computer and use it in GitHub Desktop.
Node.js Boilerplate
var
express = require('express'),
io = require('socket.io').listen(server, {log: false}),
mongoose = require('mongoose'),
morgan = require('morgan'),
app = express()
app.listen(8000);
console.log('Server running');
// #########################################################################
// Error handler
process.on('uncaughtException', function (exception) {
// handle or ignore error
console.log(exception);
});
// #########################################################################
// Mongodb
mongoose.connect('mongodb://localhost/test', function(err){
if(err){
console.log(err);
}else{
console.log('Connected to mongodb!');
}
});
var Item = mongoose.model('Item', {
content: String
});
// #########################################################################
// Static Routes
// // Stylus
// app.use(stylus.middleware({ src: __dirname + '/public', compress: true }));
// Expose files in public directory
app.use(express.static(__dirname + '/public'));
// #########################################################################
// Routes
// app.get('/', function(req, res){
// res.sendfile(__dirname + '/public/index.html');
// });
// #########################################################################
// Sockets
/*io.sockets.on('connection', function(socket){
// clientside = /socket.io/socket.io.js
console.log('Connection: ' + socket.id);
console.log('');
socket.emit('connected');
});*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment