A minimal Node.js web server using the core http module.
This repo is your first taste of “server-side JavaScript” without any frameworks:
- create a server
- respond to requests
- view the result in your browser
- Node.js installed (includes
node)
Verify:
node -vserver.js— a basic HTTP server that responds with plain text
From the project folder:
node server.jsYou should see:
Server running at http://127.0.0.1:3000/Open:
http://127.0.0.1:3000/
You should see:
Hello Node Server!Node can restart the server automatically when server.js changes:
node --watch server.jsNow change the response string in res.end(...), save, and refresh your browser.
Stop the server with:
Ctrl + C
const http = require("http");
http.createServer((req, res) => { ... })
The callback runs every time a request hits the server.
res.statusCode = 200res.setHeader("Content-Type", "text/plain")res.end("Hello Node Server!")
server.listen(port, hostname, () => { ... })
.
├── server.js
└── README.mdNode2Know-Learn-1.0 (see LICENSE).