/nodejs-restful-api

How to create a RESTful CRUD API using Nodejs?

Primary LanguageJavaScript

nodejs-restful-api

Sample JWT interactions This is an implementation of the excellent tutorial detailing set of simple JWT interactions.

Full tutorial

Get Running

brew is OSX-only. Node 8.10 is the currently the latest available on AWS Lambda so we're using that. Mongo runs on Docker in start:db.

brew install nvm yarn
nvm install 8.10 && nvm use 8.10
yarn install
yarn db:start
yarn start

Development

Postman helps with interacting with your server in a nice GUI. You can import the postman_collection to Postman to install these requests.

  • POST localhost:3001/api/auth/register

  • POST localhost:3001/api/auth/login-

  • Copy the token.

  • GET localhost:3001/api/auth/me

    • Headers
      • x-access-token

RESTful API design with Node.js

How to create a RESTful CRUD API using Nodejs?

This tutorial will demo how to set up a bare bones API using mongodb as the database.

It consist of a User model and controller. The model defines the data, and the controller will contain all the business logic needed to interact with the database.

It has a db file which will be used to connect the app to the database, and an app file used for bootstrapping the application itself.

The server file is used to spin up the server and tells the app to listen on a specific port.