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

@expresso/cli

v1.1.1

Published

Expresso boilerplate as a CLI

Downloads

4

Readme

@expresso/cli

This is a little yet (hopefully) useful tool to run @expresso/app apps with (optinally) zero config. The CLI receives a file path, wich should export a function returning a request handler, or an expresso app factory (se below for details); we then read said function, wrap it with @expresso/app tell it to use @expresso/errors as error handler and, finally, run it with @expresso/server.

Usage

Single Route

When you have a simngle route, you can export that route's factory and pass it to the expresso command. The factory will receive all config propeties as defined in the config file, plus all config provided by @expresso/app

expresso route.js -s -c config.js
// route.js
const mongodb = require('mongodb')

module.exports = (config) => async (req, res, next) => {
    const mongoDbConnection = await mongodb.connect(config.mongodb.uri)
}
// config.js
module.exports = {
    name: 'my-great-app',
    mongodb: {
        uri: process.env.MONGODB_URI
    }
}

Multiple Routes

For now, if you have multiple routes, want to use custom middleware or perform any other custom initialization logic, you should provide an app factory function; the CLI will load said function and feed it to @expresso/app to initalize your application.

Note: @expresso/errors is automatically loaded for you, you don't need to load it in your factory function. An option to disable this behaviour can be added provided anyone need it (please open an issue if you do)

expresso app.js -n my-awesome-app
// app.js
module.exports = function (app, config, environment) => {
    app.get('/myroute', routeHandler)
    app.post('/myotherroute', otherRouteHandler)
}

Options

Usage:

expresso <fileName> [options]

Arguments:

  • fileName: Name of the file which exports the app or route factory

Options:

  • --single-route, -s
    • Switches single route mode on
    • Default: false
  • --config, -c
    • Path to the configuration file
    • Default: null

    Note: if you don't specify a config file, it's nice to use the name option to provide an app name for @expresso/app

  • --path, -p
    • Route path to be used, when using single route mode; ignored otherwise
    • Default: '/'
  • --name, -n
    • Application name; used by @expresso/app for console display and debugging
    • default: 'expresso-cli'

    Note: this will be overriden by the name property, if it's present on the config file.

  • --method, -m
    • HTTP method to use on single route mode; ignored otherwise
    • Default: 'get'
    • Accepted values: get, post, put, patch or delete

Contributing

As with all other expresso libs, PRs are always welcome.

  • Fork this
  • Clone your fork
  • npm i
  • Do your changes
  • npm run build
  • Test your changes (PRs for automated tests also welcome)
  • Open PR
  • Done :D

Note: Make sure your changes don't brake the build, otherwise your PR won't be accepted