Skip to content

dbarenas/generator-rest-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published