Skip to content

Instantly share code, notes, and snippets.

@alexpreynolds
Created October 25, 2022 08:02
Show Gist options
  • Save alexpreynolds/f3a7fcdf24ac8ddf67bd13f275aac6b3 to your computer and use it in GitHub Desktop.
Save alexpreynolds/f3a7fcdf24ac8ddf67bd13f275aac6b3 to your computer and use it in GitHub Desktop.
Basic local web server running on port 3000
const PORT_NUMBER = 3000;
// Requiring express for routing
const express = require('express');
// Creating app from express
const app = express();
// Requiring in-built file system
const fs = require('fs');
// GET request to the root of the app
app.get('/', function(req, res) {
res.sendFile(__dirname + '/index.html');
})
// Creating server at port 3000 (PORT_NUMBER)
app.listen(PORT_NUMBER, function(req, res) {
console.log(`Server started on port ${PORT_NUMBER}; visit http://localhost:${PORT_NUMBER}`);
})
@alexpreynolds
Copy link
Author

Make sure that index.html is in the same directory, and then run node app.js (assuming Nodejs is installed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment