Node icon

Building a Production Ready Node.js JSON API

Outline

In recent years, Javascript has become one of the most popular programming languages used by developers due to the global prevalence of internet access, mobile devices, increased computational capacity (thanks to Moore's Law), and the fact that Javascript is the only language that will run in a web browser.

But what if you could also write backend Javascript applications? That way you could master one language instead of trying to juggle multiple syntax differences in your head during day to day development.

This is one of the key reasons many people use Node: you can learn one language, Javascript, and then use it to build every part of your full stack applications. Further, Node is an asynchronous event-driven runtime which means it provides excellent performance for applications that require lots of small tasks done in parallel (i.e. it allows for high concurrency). This is a typical requirement for highly trafficked API endpoints, so building backend applications with Node can make scaling certain types of applications substantially easier.

What you will learn

This tutorial will teach you how to use Node as an API. To do this, we'll set up Express for server logic and will be using MongoDB for the database (which is a popular choice in the Node community, as MongoDB stores data in the JSON format).

We will be building a backend that will provide the functionality for our Medium clone called Conduit. Check out the live demo of Conduit to get an idea of the functionality of what we're about to build.

Note that this course only goes over how to build the backend in Node.js. Once the backend is completed, you can complete any one of our frontend courses to create a client for the backend you've built.

Prerequisites

This tutorial assumes some basic Javascript knowledge. Familiarity with Node, Express, and MongoDB are beneficial but not necessary, as we provide links to external resources throughout this course that will fill in any knowledge gaps you may have.

Environment setup

Install Node

You can download Node from their main website which includes a built in installer. Alternatively, Node can be installed via most package managers.

Project setup

We've provided a specification for our API that we will be building. We recommended that you go over all the endpoints in the specification and play around with the demo to get a good idea of the application.

Review the API documentation
Clone the seed project

To clone the seed branch of this repo, run the following command:

git clone -b 00-seed git@github.com:gothinkster/node-express-realworld-example-app.git

If that doesn't work try

git clone -b 00-seed https://github.com/gothinkster/node-express-realworld-example-app.git
Run npm install to install all the required modules for this project

The seed repository has all the modules required for this project denoted in its package.json. You can use npm (which should've automatically been installed with Node) to install all of the necessary modules locally.

Recommendations for Completing this Tutorial

Throughout the course of this tutorial, links to additional concepts and information will be included. You can use these links as supplementary material which can help you gain insight into the stack and its various components. As always, if you have any questions Google and Stack Overflow are your best bet. If you're unsure about something specific to this tutorial, we're always around to help in the Thinkster Pro Slack channel.

We at Thinkster are firm believers in actually writing code. Therefore we strongly encourage you to type out all the code instead of copy+pasting it.

With that out of the way, let's start building out our API!

 

I finished! On to the next chapter