Jump To …

server.js

Expressling
Copyright (c) 2011 Nick Baugh (niftylettuce@gmail.com)
MIT Licensed

Open source node.js + express application framework.

This was inspired by several node.js projects.

Expressling

Express

var express = require('express')
  , app     = express.createServer()

Common

  , fs  = require('fs')

Config

Based on your project's needs, you should configure package.json accordingly to the npm packages used.

  , config = require('./config')

Settings

  , settings = require('./settings')

Environment

  , env  = process.env.NODE_ENV || 'development'
  , port = process.env.PORT || config[env].port

Mongoose

  , mongoose      = require('mongoose')
  , mongooseTypes = require("mongoose-types")

Database

You might want to use MongoHQ for production or try another provider if MongoHQ doesn't satisfy your needs.

Use either a mongodb:// URI or pass host, database, port, options.

  , db = mongoose.connect(
    config[env].db.host,
    config[env].db.database,
    config[env].db.port
  );

Load mongooseTypes

You may want to allow all types (e.g. both email and url)

mongooseTypes.loadTypes(mongoose, 'email');

Load settings

settings.bootApplication(app, db);
settings.bootRoutes(app, db);
settings.bootErrorConfig(app);

Start server

app.listen(port);
var appPort = app.address().port + '', // stringify that int!
    appEnv = app.settings.env.toUpperCase();

Colorful status

console.log(''
  + '\n  EXPRESSLING SERVER LISTENING ON PORT '.rainbow
  + " ".white.inverse
  + appPort.white.inverse
  + " ".white.inverse
  + ' IN '.rainbow
  + " ".white.inverse
  + appEnv.white.inverse
  + " ".white.inverse
  + ' MODE '.rainbow
);