npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

expressopot

v0.0.6

Published

A little bit nicer way to config express.js

Downloads

14

Readme

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:
  • 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;