Created
October 25, 2022 08:02
-
-
Save alexpreynolds/f3a7fcdf24ac8ddf67bd13f275aac6b3 to your computer and use it in GitHub Desktop.
Basic local web server running on port 3000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Make sure that
index.html
is in the same directory, and then runnode app.js
(assuming Nodejs is installed).