Skip to content
Demonstrate the structuring of an Express.JS application
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin
login
middleware
people
public/stylesheets
routes
scripts
views
.gitignore
README.md
app.js
config.js
mongo_express_config.js
package.json
testserver.js

README.md

express-crud

Demonstrate the structuring of an Express.JS application

Getting Started

Checkout and change into directory. Then execute:

npm install
npm start

Overview

Create the directory structure for each module:

    my_module
        +-- index.js
        +-- model.js
        +-- routes.js

The index.js exports only the stuff that you want to be exposed to the outside of the module to ensure data encapsulation:

    module.exports = {
        routes: require('./routes')
    };

In your app.js, import the module and use routes (or other objects) from the module:

    var my_module = require('./my_module');
    app.use('/my_module', my_module.routes);
You can’t perform that action at this time.