A Yeoman generator for building a REST API in minutes using Express + MongoDB.
JavaScript CSS
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
resource
test
.gitignore
.jshintrc
.travis.yml
LICENSE
README.md
angularUtil.js
package.json

README.md

Express + MongoDB REST API Generator Build Status

A Yeoman generator for building a REST API in minutes using Express + MongoDB.

The main generator will scaffold a project that is identical to the express command line generator as of express 3.4.2.

The rest-rest generator adds the following: 1 A resource generator for generating the routes and queries required to offer basic CRUD operations on the resource. 2 Scaffolding for a connection to a MongoDB instance using the Mongoose driver. 3 A basic logger using winston

Resource Generator

The resource generator will generate the routes and queries required to offer basic CRUD operations on the resource.

All CRUD APIs follow the convention:

ActionHTTP Verbpath
CreatePOST/resource
ReadGET/resource/:id
UpdatePUT/resource/:id
DeleteDELETE/resource/:id
Get the full listGET/resource

If you wish to customize the code that has been generated, here's where to look:

  • The routes are defined in ./routes/index.js
  • The Schema is defined in lib/db.js
  • The quries are defined in resource/.js

MongoDB Connection

Mongoose is currently being used as the MongoDB driver. The file lib/db.js contains the connection and schema definition.

Logging

A basic logger is created, the details are in the file lib/log.js. By default it creates a log file named logs/development.log. If the environment variable NODE_ENV is set to 'production' then the file will be named logs/production.log.

Dependencies

  1. Make sure you have yo installed on the latest version.
    $ npm install -g yo
  2. Ensure that MongoDB is installed and running.

Getting started

  1. Install the generator

    $ npm install -g generator-rest-express
  2. Create a project directory and run the generator

    $ mkdir myApp
    $ yo rest-express
  3. Reply to the prompts asking you for your MongoDB connection details

    $ [?] IP address where MongoDB is running? (127.0.0.1)
    $ [?] Database name? (myApp)
  4. Generate your first resource API

    $ yo rest-express:resource user
  5. Start your node server

    $ node app.js
  6. Create a few resources using curl

    $ curl -d "firstname=Brian" http://localhost:3000/users
    $ curl -d "firstname=Jerry" http://localhost:3000/users
  7. Retreive the list resources using curl

    $ curl http://localhost:3000/users

License

MIT License