Current way of working for an API

  1. Generate express
    1. express -H <app-name>
    2. npm install
  2. Init git
    1. git init
    2. create GitHub repository
    3. add git remote
  3. Configure environment
    1. npm install dotenv
    2. add require(‘dotenv’).config()
    3. create local .env file
  4. Set up authentication (Passport)
    1. following
    2. This should be read as well (using redis for express session management)
    3. npm install passport express-session connect-redis
  5. todo: Set up logger
  6. todo: Set up linting
  7. todo: Set up testing
  8. Set up database
    1. MongoLabs
    2. Add connect string in .env
    3. initialize mongoose connection in app.js
    4. write DB-specific stuffs in DA
  9. setup CORS middleware
    1. var allowCrossDomain = function(req, res, next) {
      res.header(‘Access-Control-Allow-Origin’, ‘*’);
      res.header(‘Access-Control-Allow-Headers’, ‘Content-Type’);
  10. Create architecture folders (or files without a feature folder)
    1. routes
      1. Responsibility: define endpoints and forward them to controller
    2. controllers
      1. Responsibility: use domain and send response
    3. repositories
      1. Responsibility: ensure that the right domain objects are in memory
      2. Convert data to models
      3. Interesting:
    4. models
      1. Define domain objects
    5. DA
      1. Responsibility: Handle db-specific stuff.
      2. Should only return raw data (json)
    6. (commands)
    7. views: take care on how to setup partials and layout views (
Current way of working for an API

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s