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

generator-opium

v0.2.7

Published

A simple Yeoman generator for creating APIs using Node and Express

Downloads

12

Readme

Opium generator

A simple Yeoman generator for creating APIs using Node and Express.

##Features

  • Provides a directory structure similar to generator-angular-fullstack
  • Includes Yeoman sub-generators for api routes, application components and helper functions
  • Testable: each sub-generator also generates test skeletons

Usage

Assuming you already have Node installed, run:

npm install -g yo mocha supervisor jshint

Install Opium generator:

npm install -g generator-opium

Next, to create a project:

mkdir FooBar
cd FooBar
yo opium

The generator will then ask you to provide the application name (by default it will take the folder name, in this case FooBar) and it will create some skeleton files as well as installing dependencies.

After this you can run npm start, which will automatically run linting and tests before starting the server on http://localhost:9000. The server will automatically restart itself when you modify and save a file.

Folder structure

For the FooBar project:

FooBar
├── api
│   └── thing
│       ├── index.js ............... 'thing' specific routes (like '/thing/:id')
│       └── thing.controller.js .... 'thing' specific methods (like 'ThingController.GetById`)
├── components
│   └── something
│       └── index.js ............... main logic of the 'something' component
├── config
│   ├── environment
│   │   ├── development.js ......... development specific configuration
│   │   └── production.js .......... production specific configuration
│   ├── cors.js .................... Express middleware for enabling CORS
│   └── express.js ................. Express configuration
├── lib
│   └── helper.js .................. main logic of the 'helper' helper function
├── node_modules
├── public ......................... static files served by the server (if any)
├── test ........................... unit tests (follows the application folder structure)
├── .gitignore
├── .jshintignore
├── .stylishcolors
├── .package.json
├── foo-bar.js ..................... main application file
└── routes.js ...................... main application routes

Sub-generators

Opium provides a set of sub-generators to create application parts. Each sub-generator will:

  • Create one or more skeleton files for the application part type (api route, application component, helper function)
  • Create a skeleton unit test in /test
  • Update routes.js with the new route (apiroute sub-generator)

There are three sub-generators:

  • apiroute (usage: yo opium:apiroute thing)
  • component (usage: yo opium:component something)
  • lib (usage: yo opium:lib helper)

The name parameter passed in (e.g. thing) will be used for route, folder and/or file names.

Note: if you pass in something like my-awesome-stuff, myAwesomeStuff or "my awesome stuff" the name will be normalized: using kebab-case for the routes, files and folders and CamelCase for the function names (Special case styles).

npm scripts

  • lint: runs linting using the configuration from .jshintrc file. Usage: npm run lint
  • start: starts the server using node-supervisor (it automatically runs lint and test before). Usage: npm start
  • test: runs the unit tests in the /test folder using mocha (it automatically runs lint before). Usage: npm test

License

MIT License