Developing a RESTful API

Let's do a little more work setting up our SPA by building out some resourceful routing as part of a RESTFul API that we can connect later to our database and our client-side code. We're lucky that Express has such a vibrant community of developers building many add-ons, and we're going to use one for resourceful routing.

Installing resourceful routing

The first thing we need to do is to install our module, which will provide us with some resourceful routing:

npm install resource-routing -save

This installs the resourceful routing plugin we're going to use, and saves a reference to the package.json file.

Next, we need to do some setup in our app.js file:

var express = require('express'); var path = require('path'); var favicon ...

Get Mastering JavaScript Single Page Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.