Skip to content

Instantly share code, notes, and snippets.

@abonello
Last active March 20, 2026 09:08
Show Gist options
  • Select an option

  • Save abonello/43782e019237ed4ea4fd1fa67149980f to your computer and use it in GitHub Desktop.

Select an option

Save abonello/43782e019237ed4ea4fd1fa67149980f to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h1>Server</h1>
</body>
</html>
const http = require('http')
const fs = require('fs')
const port = 3000
const server = http.createServer(function(req, res) {
//res.write('Hello World')
res.writeHead(200, { 'Content-Type': 'text/html' })
fs.readFile('index.html', function(error, data) {
if (error) {
res.writeHead(404)
res.write('Error: File not found')
} else {
res.write(data)
}
res.end()
}
// res.end()
})
server.listen(port, function(error) {
if (error) {
console.log('Something went wrong', error)
} else {
Console.log('Server is listening on PORT:', port)
}
}
// To run server use: node NodeServer.js

Comments are disabled for this gist.