codegurukool.com · Free coding tutorials & online compiler

Home › Node.js Tutorial › Node.js Express basics

Node.js Express basics

A popular web framework.

Express makes servers shorter: install it with npm install express, then define routes with app.get. This example imitates routing in plain JavaScript.

Example code

const routes = { "/": "Home", "/about": "About" };
function get(p) { return routes[p] || "Not found"; }
console.log(get("/about"));
console.log(get("/x"));

Run this code in the online editor

← Node.js NPM and package.jsonNode.js errors →