nopalm
Version:
One stop graphical solution to create and manage your local Node.Js projects end to end.
26 lines (22 loc) • 673 B
JavaScript
const http = require('http');
const fs = require('fs');
const path = require('path');
const server = http.createServer((req, res) => {
// Get the file path to serve
const filePath = path.join(__dirname, 'public', 'index.html');
// Read the HTML file
fs.readFile(filePath, (err, data) => {
if (err) {
res.writeHead(500, { 'Content-Type': 'text/plain' });
res.end('500 Internal Server Error');
} else {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(data);
}
});
});
// Start the server on port 3000
const PORT = 3000;
server.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});