git clone https://github.com/moudy/expressjs-base new-project
cd new-project
rm -rf .git
npm install
Live example on Heroku. Remember to run heroku config:set NODE_ENV=production
when deploying fo the first time.
app.js
is the entery point for the app. The Express app is created here- In development/testing environments dotenv loads
.env.development
and.env.testing
config/boot.js
gets called passing in app instance- Some basic settings are added to app (port, title, view engine, etc.)
config/initializers/*
are called. This is where you can add other setup code like passport configuration- Some basic middleware is defined
- Map
config/routes.js
and use router as middleware
- connect to Database by requiring
config/db.js
- Start app with
app.listen()
Routes are defined in config/routes.js
. See Project Router for more info.
module.exports = function () {
this.get('/', 'pages/index');
};
Views are located in app/views
. express-handlebars is used as the view engine. Despite it's name it works fine with Express 4. The view engine is configured in config/view
. Handlebars is passed into the express3-handlebars module so you can be sure which version of handlebars you are using. This can be important if you also want to use handlebars on the client.
SASS + Browserify. Images referenced in CSS are converted to Base64 strings. Assets are served using Broccoli as middleware. See Brocfile.js
for configuration.
A postinstall script builds fingerprinted and gziped assets into assets/
using Broccoli. You can optionally provide some AWS credentials as environment variables and script/deploy-assets
will deploy the assets to an S3 bucket. Make sure to specify the bucketname and change the asset host in config/environments/production.js
. The asset-url
handlebars helper (in lib/handlebars-helpers.js
) takes care of the url re-writing based on the asset host and fingerprint.
A basic starting point for mocha tests in test/
Should go in app/models/
. config/db.js
and test/helpers
assumes the use of MongoDB/MongooseJS but can be easily swapped out if that's not right for the application.