Socket
Socket
Sign inDemoInstall

expressopot

Package Overview
Dependencies
1
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    expressopot

A little bit nicer way to config express.js


Version published
Maintainers
1
Install size
1.18 MB
Created

Readme

Source

expressopot

A little bit nicer way to configure express.js

Usage:

var express = require('express');
var expressopot = require('expressopot');

var config = require('./config');

var app = expressopot(express(), config);

// Some other stuff

module.exports = app;

Why is this needed?

Tell you the truth, this is not strictly needed. This project came from personal problems with the way how Express is "traditionally" configured. After using frameworks such as Django, the Express configuration seemed rather ugly and hard to read. While it is more "Javascript-like" way to do the configuration (meaning configuration by using code), I found Django's configuration dictionary easier to read.

What I am trying to say is that this is just an alternate way to configure Express, not that it is some sort of silver bullet :).

Currently supported properties:

  • views

    • Type: Object
    • Valid keys/values:
      • path: String. Path to view folder.
      • engine: String. View engine.
  • middleware

    • Type: Object
    • Valid keys:
      • pre: Array. List of the middleware to be run (functions).
      • post: Array. List of the middleware to be run (functions).
      • http_errors:
        • Type: Object
        • Valid keys/values:
          • key: Number. HTTP status code.
          • value: Handler function or an object containing the handlers. If the value is an object, it must contain at least one of the following pairs:
            • "production": Function
            • "development": Function. If only one is specified in the object, it will be used for both cases.
      • parameters:
        • Type: Object
        • Valid keys/values:
          • key: String. Name of the parameter.
          • value: Function. Callback function.
        • See: Express API Documentation: app.param()
  • routes

    • Type: Object
    • Valid keys/values:
      • key: String. Path.
      • value: Router. Router that handles the requests to the specified path.
  • locals

Example config file:

const express = require('express');
const path = require('path');
const logger = require('morgan');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');

var cors = require('./middleware/cors').handler;
var e404 = require('./middleware/error/404').handler;
var e500 = require('./middleware/error/500');

var recipes = require('./routes/recipes');
var tags = require('./routes/tags');
var ingredients = require('./routes/inredients');
var units = require('./routes/units');

const config = {
  views: {
    path: path.join(__dirname, 'views'),
    engine: 'jade'
  },
  middleware: {
    pre: [
      cors,
      logger('dev'),
      bodyParser.json(),
      bodyParser.urlencoded({ extended: false }),
      cookieParser(),
      express.static(path.join(__dirname, 'public'))
    ],
    http_errors: {
      404: e404,
      500: e500
    }
  },
  routes: {
    '/api/recipes': recipes,
    '/api/tags': tags,
    '/api/ingredients': ingredients,
    '/api/units': units
  },
  locals: {
    foo: 'bar'
  }
};

module.exports = config;

Keywords

FAQs

Last updated on 16 Oct 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc