Note that there are some explanatory texts on larger screens.

plurals
  1. POExpressJS How to structure an application?
    primarykey
    data
    text
    <p>I'm using the ExpressJS web framework for NodeJS.</p> <p>People using ExpressJS put their environments (development, production, test...), their routes etc on the <code>app.js</code>. I think that it's not a beautiful way because when you have a big application, app.js is too big!</p> <p>I would like to have this directory structure:</p> <pre><code>| my-application | -- app.js | -- config/ | -- environment.js | -- routes.js </code></pre> <p>Here's my code:</p> <p><strong>app.js</strong></p> <pre><code>var express = require('express'); var app = module.exports = express.createServer(); require('./config/environment.js')(app, express); require('./config/routes.js')(app); app.listen(3000); </code></pre> <p><strong>config/environment.js</strong></p> <pre><code>module.exports = function(app, express){ app.configure(function() { app.use(express.logger()); }); app.configure('development', function() { app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); }); app.configure('production', function() { app.use(express.errorHandler()); }); }; </code></pre> <p><strong>config/routes.js</strong></p> <pre><code>module.exports = function(app) { app.get('/', function(req, res) { res.send('Hello world !'); }); }; </code></pre> <p>My code works well and I think that the structure of the directories is beautiful. However, the code had to be adapted and I'm not sure that it's good/beautiful.</p> <p>Is it better to use my structure of directories and adapt the code or simply use one file (app.js)?</p> <p>Thanks for your advices!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload