Introduction
Welcome! 👋 This documentation will guide you through setting up a Node.js project for building small to medium-scale RESTful APIs using Express.js. The aim is to provide a sustainable structure that simplifies complex projects into smaller, more reusable, and modular components. We will also focus on best practices and various ways to optimize workflow when working collaboratively.
Node.js (or informally Node) is an open-source, cross-platform runtime environment that allows developers to run JavaScript on the server. Node provides an environment to run scripts server-side to produce dynamic web content for the client.
Express.js is an unopinionated and fairly minimalist Node web framework that provides a robust set of features to develop production-ready web and mobile applications.
Intended Users
This documentation is targeted towards the following users:
- Beginner to intermediate developers who need to setup a backend for a personal project.
- Software development teams working on small or medium-sized web applications.
Prerequisite Knowledge
The documentation assumes the following:
- Working knowledge of JavaScript(ES6), HTML, CSS - you are expected to know how to write basic HTML and CSS to make a simple static website.
- Ability to use the terminal to run simple commands.
- Working knowledge of Node.js - you should be familiar with using a package manager such as
npm
oryarn
to install Node.js packages or modules.
Software Requirements
Before proceeding, ensure you have the following installed:
- Node.js v14.x or later
- Npm Package Manager v7.x or later
- Visual Studio Code
Although any screenshots provided will be from VS Code, most of the instructions in this documentation are independent of your IDE. IDEs such as Visual Studio, WebStorm, and Atom are also viable alternatives.
Procedures Overview
The main sections of the documentation are summarized below:
- Elaboration on Project Structure
- Configuring Project for Collaboration
- Installing Express.js
- Adding Routes
- Middleware
Typographical Conventions
-
Some code snippets may have clickable numbers that can be useful if you do not understand the function of a piece of code. Code snippets can be copied by clicking the icon in the top right corner. See an example of this below:
const sum = (numbers) => { return numbers.reduce((a, b) => a + b, 0); // (1) };
- Return the sum of the numbers in the list.
-
Modifications made to previously created files will be highlighted in yellow:
const sum = (numbers) => { const multiplier = 2; return numbers.reduce((a, b) => multiplier * (a + b), 0); };
-
File names, npm packages, npm scripts will be formatted similar to:
somefile.js
. -
Instructions that require you to run a command in terminal will be formatted like:
run some command in the terminal
Notes and Warning Messages
Throughout the documentation, we will use message blocks to inform you of relevant information. Each possible message block, from most important to least important:
Danger
Specifies actions that may cause an error or will cause the application to crash.
Warning
Specifies content that must be read before proceeding.
Info
Indicates additional information or tips.
Success
Indicates what success looks like.