matthoiland / node-rest-api

NodeJS API starter project

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NodeJS API Starter

Stop being dumb and start being smart.

Tools and Practices Used

  • NodeJS w/Express Framework
  • MongoDB w/Mongoose ORM
  • OAuth 2.0
  • REST Interface w/JSON API(-ish) responses
  • Web Sockets for resource events
  • Cucumber acceptance testing
  • Component-based Structure
  • Async/Await
  • mjs file extensions
  • Winson event logging

Setup

Prerequisites

Make sure that Node, Mongo, and Redis are installed on your machine. If not, install these with Homebrew.

brew install node
brew install mongodb
brew services start mongodb
brew install redis
brew services start redis
redis-cli ping
Environment Config File

Create a file called .env in the root directory. This is just for local development – in production you'll set these as environment variables on your server.

SECRET=secret-string-for-tokens-and-encryption
EXAMPLE_CLIENT_ID=123456ab-cdef-ghij-klmn-opqrstuvwxyz
EXAMPLE_CLIENT_SECRET=123456ab-cdef-ghij-klmn-opqrstuvwxyz
BASE_URL=
MONGODB_URI=
REDIS_URL=
Run
# Install dependencies
npm install

# Development
npm run dev

# Production
npm start

Rules of Thumb

Writing Code
Error Codes

Keep the status codes simple - try to stick to these.

  • 200 – OK
  • 201 – Created
  • 204 – No Content
  • 304 – Not Modified
  • 400 – Bad Request
  • 401 – Unauthorized
  • 403 – Forbidden
  • 404 – Not Found
  • 410 – Gone
  • 500 – Internal Server Error

About

NodeJS API starter project

License:MIT License


Languages

Language:JavaScript 99.3%Language:Gherkin 0.7%