DEV Community

Royal Jain
Royal Jain

Posted on

Contribute to Open-Source: A step-by-step guide for Express NodeJs

Express is a minimal and flexible Node.js web application framework for Node. It’s top features include DSL for routing, HTTP helpers like redirection, caching, cookie management etc with focus on high performance

We will explore the internals of express through a series of tasks of increasing complexity and scope. Each task will have a scope and runtime with it so you can get started without the setup load.


Repository Overview

Express is a lightweight framework which relies on developers adding custom middleware for their specific use case. It relies on Node’s http server to run and adds some core objects like

  • Request - Object which handles request parsing for headers, fresh / stale, checking for proxy etc
  • Response - Object for sending response (setting headers, attaching files, response codes etc)
  • Router - Core routing logic ( setting up API path’s and corresponding functions) + framework for adding Middleware

Middlewares provide custom functionality and can be added by using app.use interface

  • Middleware - Adding functionality to express like cookie-parsing, cors etc can be done by adding middleware functions which can alter request and response object. In-depth.
  • Application - Finally everything is wrapped around in the Application Object

Tasks

Task #1: Add default port 1994 to the express server

Description: Express has a default port of 3000, try changing this to 1994. Get yourself familiar with lib/express.js and lib/application.js. Ignore other files for now.

Scope:

  1. lib/application.js
  2. lib/express.js

Hint: Searching for app.listen will be a good starting point

Run Task

Checkout complete tutorial at Full Tutorial

Top comments (0)