{ res.writeHead(200, {"Content-Type": "text/html"}); res.end("

Hel..."> { res.writeHead(200, {"Content-Type": "text/html"}); res.end("

Hel...">

Node.js Tutorial - Getting Started

Node.js Basics

const http = require("http");

const server = http.createServer((req, res) => {
    res.writeHead(200, {"Content-Type": "text/html"});
    res.end("<h1>Hello</h1>");
});

server.listen(3000, () => {
    console.log("Server running on port 3000");
});

Express.js

const express = require("express");
const app = express();
app.get("/", (req, res) => res.send("Hello"));
app.post("/api/users", (req, res) => res.json(req.body));
app.listen(3000);

Summary

  • Node.js runs JavaScript on the server
  • Express simplifies HTTP server creation
← Android Tutorial - Getting StajQuery Tutorial - Getting Star β†’