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

expressjs-api

v0.1.0

Published

Yeoman generator for creating Web APIs using MongoDB/Sequelize (MySQL, Postgres, etc), Express, and Node

Downloads

4

Readme

Mayank API generator

Yeoman generator for creating API's using MongoDB/Sequelize (Mysql, Postgres, sqlite), Express, and Node - lets you quickly set up a project following best practices.

Generated project:

Usage

Install yo, grunt-cli, and expressjs-api:

npm install -g yo grunt-cli expressjs-api generator-expressjs-api

Make a new directory, and cd into it:

mkdir my-new-project && cd $_

Run yo expressjs-api, optionally passing an app name:

yo expressjs-api [app-name]

Run grunt for building, grunt serve for preview, and grunt serve:dist for a preview of the built app.

Prerequisites

  • MongoDB - Download and Install MongoDB - If you plan on scaffolding your project with mongoose, you'll need mongoDB to be installed and have the mongod process running.

Supported Configurations

General

  • Build Systems: Grunt, Gulp (Coming Soon)
  • Testing:
    • Jasmine
    • Mocha + Chai + Sinon
      • Chai assertions:
        • Expect
        • Should

Server

  • Scripts: Babel
  • Database:
    • None,
    • MongoDB, SQL
      • Sequelize (SQL) Table Options: Timestamps, Paranoid, Pluralized Names
      • Authentication boilerplate: Yes, No
      • oAuth integrations: Facebook Twitter Google
      • Socket.io integration: Yes, No

Generators

Available generators:

App

Sets up a new ExpressJS API Boilerplate with best practices

Usage:

Usage:
  yo expressjs-api:app [options] [<name>]

Options:
  -h,   --help          # Print the generator's options and usage
        --skip-cache    # Do not remember prompt answers                        Default: false
        --skip-install  # Do not install dependencies                           Default: false
        --app-suffix    # Allow a custom suffix to be added to the module name  Default: App

Arguments:
  name    Type: String  Required: false

Example:

yo expressjs-api

Endpoint

Generates a new API endpoint.

Usage:

Usage:
  yo expressjs-api:endpoint [options] <name>

Options:
  -h,   --help               # Print the generator's options and usage
        --skip-cache         # Do not remember prompt answers           Default: false
        --route              # URL for the endpoint
        --models             # Specify which model(s) to use
        --endpointDirectory  # Parent directory for enpoints

Arguments:
  name    Type: String  Required: true

Example:

yo expressjs-api:endpoint message
[?] What will the url of your endpoint be? /api/messages

Produces:

server/api/message/index.js
server/api/message/index.spec.js
server/api/message/message.controller.js
server/api/message/message.integration.js
server/api/message/message.model.js  (optional)
server/api/message/message.events.js (optional)
server/api/message/message.socket.js (optional)

###Openshift

Deploying to OpenShift can be done in just a few steps:

yo expressjs-api:openshift

A live application URL will be available in the output.

oAuth

If you're using any oAuth strategies, you must set environment variables for your selected oAuth. For example, if we're using Facebook oAuth we would do this :

rhc set-env FACEBOOK_ID=id -a my-openshift-app
rhc set-env FACEBOOK_SECRET=secret -a my-openshift-app

You will also need to set DOMAIN environment variable:

rhc set-env DOMAIN=<your-openshift-app-name>.rhcloud.com

# or (if you're using it):

rhc set-env DOMAIN=<your-custom-domain>

After you've set the required environment variables, restart the server:

rhc app-restart -a my-openshift-app

To make your deployment process easier consider using grunt-build-control.

Pushing Updates

grunt

Commit and push the resulting build, located in your dist folder:

grunt buildcontrol:openshift

Heroku

Deploying to heroku only takes a few steps.

yo expressjs-api:heroku

To work with your new heroku app using the command line, you will need to run any heroku commands from the dist folder.

If you're using mongoDB you will need to add a database to your app:

heroku addons:create mongolab

Your app should now be live. To view it run heroku open.

If you're using any oAuth strategies, you must set environment variables for your selected oAuth. For example, if we're using Facebook oAuth we would do this :

heroku config:set FACEBOOK_ID=id
heroku config:set FACEBOOK_SECRET=secret

You will also need to set DOMAIN environment variable:

heroku config:set DOMAIN=<your-heroku-app-name>.herokuapp.com

# or (if you're using it):

heroku config:set DOMAIN=<your-custom-domain>

To make your deployment process easier consider using grunt-build-control.

Pushing Updates

grunt

Commit and push the resulting build, located in your dist folder:

grunt buildcontrol:heroku

Configuration

Yeoman generated projects can be further tweaked according to your needs by modifying project files appropriately.

A .yo-rc file is generated for helping you copy configuration across projects, and to allow you to keep track of your settings. You can change this as you see fit.

Testing

Running grunt test will run the client and server unit tests with karma and mocha.

Use grunt test:server to only run server tests.

Protractor tests

To setup protractor e2e tests, you must first run

npm run update-webdriver

Use grunt test:e2e to have protractor go through tests located in the e2e folder.

Code Coverage

Use grunt test:coverage to run mocha-istanbul and generate code coverage reports.

coverage/server will be populated with e2e and unit folders containing the lcov reports.

The coverage taget has 3 available options:

  • test:coverage:unit generate server unit test coverage
  • test:coverage:e2e generate server e2e test coverage
  • test:coverage:check combine the coverage reports and check against predefined thresholds
  • when no option is given test:coverage runs all options in the above order

Debugging

Use grunt serve:debug for a more debugging-friendly environment.

Environment Variables

Keeping your app secrets and other sensitive information in source control isn't a good idea. To have grunt launch your app with specific environment variables, add them to the git ignored environment config file: server/config/local.env.js.

Project Structure

Overview

└── server
    ├── api                 - Our apps server api
    ├── auth                - For handling authentication with different auth strategies
    ├── components          - Our reusable or app-wide components
    ├── config              - Where we do the bulk of our apps configuration
    │   └── local.env.js    - Keep our environment variables out of source control
    │   └── environment     - Configuration specific to the node environment

An example server component in server/api

thing
├── index.js                - Routes
├── thing.controller.js     - Controller for our `thing` endpoint
├── thing.model.js          - Database model
├── thing.socket.js         - Register socket events
└── thing.spec.js           - Test