server.js | |
---|---|
| |
| |
| |
| |
This was inspired by several node.js projects. | |
Expressling | |
Express | var express = require('express')
, app = express.createServer() |
Common | , fs = require('fs') |
ConfigBased on your project's needs, you should configure | , 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") |
DatabaseYou might want to use MongoHQ for production or try another provider if MongoHQ doesn't satisfy your needs.
Use either a | , db = mongoose.connect(
config[env].db.host,
config[env].db.database,
config[env].db.port
); |
Load mongooseTypesYou 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
);
|