1. Home
  2. /
  3. Express-js
  4. /
  5. Express.js Simple API

Express.js Simple API - Express-js Typing CST Test

Loading…

Express.js Simple API — Express-js Code

Demonstrates a simple Express.js REST API with basic routes and middleware.

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

app.use(express.json())

app.get('/', (req, res) => {
	res.send('Hello, Express!')
})

let count = 0
app.get('/counter', (req, res) => {
	res.json({ count })
})
app.post('/counter/increment', (req, res) => {
	count++
	res.json({ count })
})
app.post('/counter/decrement', (req, res) => {
	count--
	res.json({ count })
})
app.post('/counter/reset', (req, res) => {
	count = 0
	res.json({ count })
})

app.listen(port, () => {
	console.log(`Server running at http://localhost:${port}`)
})

Express-js Language Guide

Express.js is a fast, minimalist web framework for Node.js. It simplifies building web servers, RESTful APIs, and backend services, providing robust routing, middleware support, and HTTP utility methods.

Primary Use Cases

  • ▸Building RESTful APIs and web services
  • ▸Creating backend for web and mobile apps
  • ▸Server-side rendered web applications
  • ▸Rapid prototyping of server logic
  • ▸Microservice architecture backends

Notable Features

  • ▸Fast and minimalist core
  • ▸Middleware support for request/response processing
  • ▸Flexible routing and URL handling
  • ▸Integration with databases (MongoDB, MySQL, PostgreSQL)
  • ▸Compatible with templating engines (EJS, Pug, Handlebars)

Origin & Creator

Express.js was created by TJ Holowaychuk in 2010 as a lightweight and flexible web framework for Node.js.

Industrial Note

Express.js is preferred for building REST APIs, microservices, and server-side rendered applications where simplicity, speed, and middleware flexibility are crucial.

More Express-js Typing Exercises

Express.js Query Params ExampleExpress.js URL Params ExampleExpress.js JSON Body ExampleExpress.js Middleware ExampleExpress.js Static Files ExampleExpress.js Router ExampleExpress.js Error Handling ExampleExpress.js CORS ExampleExpress.js Environment Variables Example

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher