gothinkster/node-express-realworld-example-app

Name: node-express-realworld-example-app

Owner: Thinkster

Description: null

Created: 2016-07-15 09:41:40.0

Updated: 2018-01-18 19:03:23.0

Pushed: 2018-01-07 04:59:27.0

Homepage: null

Size: 80

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Node/Express/Mongoose Example App

Build Status

Example Node (Express + Mongoose) codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld API spec.

This repo is functionality complete ? PRs and issues welcome!

Getting started

To get the Node server running locally:

Alternately, to quickly try out this repo in the cloud, you can Remix on Glitch

Code Overview

Dependencies
Application Structure
Error Handling

In routes/api/index.js, we define a error-handling middleware for handling Mongoose's ValidationError. This middleware will respond with a 422 status code and format the response to have error messages the clients can understand

Authentication

Requests are authenticated using the Authorization header with a valid JWT. We define two express middlewares in routes/auth.js that can be used to authenticate requests. The required middleware configures the express-jwt middleware using our application's secret and will return a 401 status code if the request cannot be authenticated. The payload of the JWT can then be accessed from req.payload in the endpoint. The optional middleware configures the express-jwt in the same way as required, but will not return a 401 status code if the request cannot be authenticated.


Brought to you by Thinkster


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.