forked from ladjs/lad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
82 lines (66 loc) · 2.28 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Expressling
// Copyright (c) 2012 Nick Baugh ([email protected])
// MIT Licensed
// Open source [node.js][1] + [express][2] application framework.
// [1]: http://nodejs.org/
// [2]: http://expressjs.com/
// * Maintainer: [@niftylettuce](https://twitter.com/#!/niftylettuce)
// * Twitter: [@expressling](https://twitter.com/#!/expressling)
// * Website: <http://expressling.com/>
// * Source: <https://github.com/niftylettuce/expressling/>
// This was inspired by several [node.js](http://nodejs.org) 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](http://npmjs.org) packages used.
//
// * <http://wiki.commonjs.org/wiki/Packages/1.0>
//
, 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](http://mongohq.com/) for production
// or try another provider if MongoHQ doesn't satisfy your needs.
//
// * <http://www.mongodb.org/display/DOCS/Connections/>
// * <http://www.mongodb.org/display/DOCS/A+Sample+Configuration+Session/>
//
// 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.bootSchemas(app, db);
// # 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
);