Skip to content

Introduction

Welcome to the Basic Express App guide 🚀

Express.js is a fast, minimalist web framework for Node.js, making it easy to build powerful and scalable web applications. Whether you're new to backend development or just getting started with Express, this guide will walk you through the fundamentals of setting up a basic Express app!

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.

JavaScript is a programming language used to make web pages interactive. It runs in the browser and on the server (with Node.js), allowing developers to create dynamic websites and applications.

Prerequisite readings:

  1. Very basic CLI (Command Line Interface) understanding.

    Basically, knowing where the CLI is located and being able to access it.

  2. Some Node.js knowledge.

    The commands will be given, but it is very much recomended to understand why they are being used.

  3. Basic JavaScript knowledge

    The commands will be given, but it is very much recomended to understand why they are being used.

  4. Basic HTML knowledge

    The text will be given, but it is very much recomended to understand why it is being used.

  5. Some GitHub understanding.

    Understanding how to create a repository. This will only be needed for hosting and a guide will be attached.

What You'll Learn 📖

  • How to install and set up Express
  • Creating a basic web server
  • Handling simple routes (GET, POST)
  • Handling different content types in Express
  • Error handling in Express
  • Running the app in a browser
  • Hosting your app

Why use Express

  • Much simpler than alternatives
  • Nicely integrated with JavaScript
  • Supports hundreds of packages
  • Vast documentation

Intended users

This guide is designed for beginners who want to learn how to set up and use Express.js to build a simple web server. It is ideal for:

  • New Developers - Those who are just starting with backend development and want an easy-to-follow introduction to Express.
  • JavaScript Learners - Developers familiar with JavaScript who want to explore how it works on the server-side.
  • Frontend Developers - Those who know HTML, CSS, and JavaScript but want to expand their skill into backend development.
  • Students & Hobbyists - Anyone curious about how to create simple APIs and web applications using Express.js

API(Application Programming Interface) is a way for different applications to communicate with each other. In web development, APIs allow clients (like browsers or mobile apps) to send requests and receive data from a server.

Software requirements

  1. Visual Studio Code (VScode)

    You will most definitely need some sort of IDE (code editing platform). For this guide specifically, Visual Studio Code IDE will be used as it is the most common choice.

  2. Node.js

    If you already have VScode installed, installing Node.js is a simple task. you can follow this guide

  3. Browser

    It is a matter of your choice, whether its Chrome, Firefox, or Tor. You will only need a browser to see how your app looks when launched.

Express installation

Once Node.js is installed, follow these steps to install Express:

1. Initialize a new Node.js project

Open your terminal and run:

npm init -y

This creates a package.json file, which manages your project dependencies.

2. Install Express Run the following command to install Express:

npm install express

This will add Express to your project and save it as a dependency.

Typographical Conventions

To maintain clarity and consistency throughout this guide, we use the following typographical conventions:

  1. Code Blocks - Used for commands, code snippets, and examples.

    Ex:

    console.log("Hello Express");
    

  2. Inline Code - Used for small code elements within a sentence.

    Ex:

    Use the app.get() method to define a route.

  3. Bold Text - Highlights important terms and concepts.

    Ex:

    Middleware functions help process requests before sending a response.

  4. Italic Text - Used for emphasis or to introduce new terms.

    Ex:

    Express is a lightweight framework for Node.js

Notes and Warning Messages

Tip

Declares a best practice method.

Example: Using req and res instead of request and response

app.get('/', (req, res) => {
res.send('hello world')
})

Danger

Declares an error/bug or a code vulnerability

Example: You should not use api/security codes in your code, instead put them in an .env file

git_api_code = 1234Abc

Success

Declares a successful completion/ expected result

Example: If you have done everything right, you should see <123> in your terminal

console.log('123')

Example

Declares a non-coding related example

Example: Describing a folder as a real life folder

Image title
Taken from Pexels: source

Note

Declares a note