Expressjs

Aliases
  • express
  • express.js
Image of Author
September 22, 2023 (last updated September 16, 2024)

https://expressjs.com/

Expressjs is a JavaScript and TypeScript minimal server framework for Nodejs. It is by a wide margin the most popular server framework in the JS ecosystem. In fact many other server frameworks wrap express.

enable json parsing

https://expressjs.com/en/api.html#req.body

import express from 'express'

const app = express();
app.use(express.json())

// post with JSON body: { data: 4 }
app.post('/api/test', (req, res) => {
  const value = req.body.data
  res.json({ value })
})

enable static files

https://expressjs.com/en/starter/static-files.html

import express from 'express';

const app = express();

// serve files from './public'
app.use(express.static('public'));

// serve files from './public' at path '/static'
app.use('static', express.static('public'));