Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

expressive

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expressive

Adds environment-specific hooks to express apps

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created
Source

Build Status downloads npm Code Climate Test Coverage dependencies

NPM info

Expressive

Installation

npm install --save expressive

Usage

var express = require('express');
var app = express();
var expressive = require('expressive');

// nconf setup not pictured
expressive(app, nconf.get('NODE_ENV')).env('development');

app.use('/normal-route', function(req, res, next) {
  next();
});

app.development.get('/dev-only-route', function(req, res, next) {
  next();
});

Expressive installs environment-specific hooks in your express app, which essentially eliminates the need to do something like

if (process.env.NODE_ENV === 'development') {
  app.use(/* some dev route */)
}

Of course, you could just use if statements like this, but I've found that expressive makes an app easier to read because all the route definitions are parallel. Additionally, testing is slightly easier because you don't have to specify a describe for each environment. You can just assert that app.environmentName exists and, if you're into this kind of thing, that it gets called with the appropriate routes and handlers.

Api

Expressive exports a single function that takes two arguments: your express app and, optionally, the current environment (defaulting to process.env.NODE_ENV). It returns an object with a single method: .env.

expressive(app)

or

expressive(app, currentEnvironment)

.env

The .env method also takes two arguments: the name of the environment to add hooks for and an optional alias for that environment. This method returns the same object (this) so you can chain your .env calls.

Example

var express = require('express');
var app = express();
var expressive = require('expressive');

expressive(app)
  .env('test')
  .env('smoktest')
  .env('development', 'dev') // Alias "dev" allows you to do app.dev.use instead of app.development.use

Contributing

Please see the contribution guidelines.

Keywords

FAQs

Package last updated on 27 Dec 2016

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc