RESTful API using Node.js, Express, and MongoDB
-
Install Node.js
-
Set a DRYWALL_MONGO environment variable (details below) or install MongoDB
-
Install the dependencies
$ npm install
- Run the node server on localhost (default port 8000)
$ npm start
-
Check that its working:
Run the app in development mode to automatically restart when you make a change to the source code.
$ grunt dev
Sanity check the code and run integration tests.
$ npm test
The following environment variables are used in this app and can be configured by creating a .env
file in the root of the project.
It should be in the format: KEY=VALUE
PORT
(default: 8000): TCP port where the app listens for HTTP requestsDRYWALL_AUTH0_CLIENT_SECRET
: Auth0 client secret for drywall. It handles user social logins.DRYWALL_AUTH0_ID
: Auth0 client id for drywall. It handles user social logins.DRYWALL_MONGOHQ_URI
: MongoHQ/compose connection string (only one MongoDB connection).DRYWALL_MONGOLAB_URI
: MongoLab connection string (only one MongoDB connection).GITHUB_CLIENT_ID
: client id from a github application. This is to allow more requests.GITHUB_SECRET
: client secret from a github application.DRYWALL_PAYPAL_LIVE_MODE
(default: false): Eithertrue
orfalse
to specify whether to use live mode credentials.- For the following,
<paypalMode>
=SANDBOX
orLIVE
. DRYWALL_PAYPAL_<paypalMode>_CLIENT_ID
: Paypal client id for this mode.DRYWALL_PAYPAL_<paypalMode>_SECRET
: Paypal secret for this mode.DRYWALL_PAYPAL_<paypalMode>_USER
: Paypal user for this mode.DRYWALL_PAYPAL_<paypalMode>_PASSWORD
: Paypal password for this mode.DRYWALL_PAYPAL_<paypalMode>_SIGNATURE
: Paypal signature for this mode.
By default the app connects to MongoDB as mongodb://localhost:27017/test
.
Auto deployment from a code branch to heroku is handled by codeship.
Environment Type | branch | URL |
---|---|---|
Staging | develop |
http://drywall-api-staging.herokuapp.com |
Production | master |
http://drywall-api-production.herokuapp.com |
To start MongoDB locally:
$ mongod
$ mongod --dbpath /data/db # specify path to db data
http://docs.mongodb.org/manual/reference/mongo-shell/
In the mongo/bin folder, run mongo
> use <dbName>
> show collections
> db.<collection>.find() //return all
> db.<collection>.find({id: 1})
> db.<collection>.remove() //Does not remove indexes
> db.<collection>.drop() //drops documents and indexes
- Generate API documentation (needs redis): https://github.com/mashery/iodocs
- Create configurable REST APIs using Mongoose schemata: https://github.com/wprl/baucis
- Create restful APIs with express: https://github.com/baugarten/node-restful