Shoulder.dev Logo Shoulder.dev

express - benhall/express-demo

Go to Shoulder Page

Express is a fast, unopinionated, minimalist web framework for Node.js. It’s used for creating web applications and APIs. In this guide, we’ll explain why Express is used and provide an example of how to get started with it.

Why Use Express?

Express is a popular choice for building web applications due to its robust routing, focus on high performance, and super-high test coverage. It also provides HTTP helpers, content negotiation, and a view system supporting over 14 template engines. Express is unopinionated, meaning it doesn’t force you to use any specific ORM or template engine.

Getting Started

To use Express in your project, first, install it using npm:

npm install express

Now, let’s create a simple Express application:

const express = require('express')
const app = express()

app.get('/', function (req, res) {
res.send('Hello World')
})

app.listen(3000)

In this example, we require the Express module, create an instance of the Express application, define a route for the root path (‘/’) that sends a ‘Hello World’ message, and start the server listening on port 3000.

Features

Express offers several features, including:

  • Robust routing
  • High performance
  • Super-high test coverage
  • HTTP helpers (redirection, caching, etc.)
  • View system supporting 14+ template engines
  • Content negotiation
  • Executable for generating applications quickly

Documentation and Community

For more information, visit the Express website and documentation. You can also join the #express channel on Libera Chat IRC, or check out the GitHub Organization for Official Middleware & Modules. For discussion and support, visit the Google Group or Gitter.

Quick Start

To quickly get started with Express, you can use the executable express(1) to generate an application:

npm install -g express-generator@4
express /tmp/foo && cd /tmp/foo
npm install
npm start

This will create a new Express application and install the necessary dependencies. You can then view the website at http://localhost:3000.

Philosophy

Express follows the philosophy of providing small, robust tooling for HTTP servers, making it a great solution for single page applications, websites, hybrids, or public HTTP APIs.

Examples

To view the examples, clone the Express repo and install the dependencies:

git clone git://github.com/expressjs/express.git --depth 1
cd express
npm install
node examples/content-negotiation

Then run whichever example you want.

Contributing

The Express.js project welcomes all constructive contributions. For more technical details on contributing, see the Contributing Guide.

Security Issues

If you discover a security vulnerability in Express, please see the Security Policies and Procedures.

Running Tests

To run the test suite, first, install the dependencies, then run npm test:

npm install
npm test