Last active
February 22, 2024 18:08
-
-
Save MessiDaGod/129f1897254bed1c0ce1b7c95d4d57b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
{ | |
"name": "example.com", | |
"version": "1.0.0", | |
"description": "", | |
"main": "main.js", | |
"scripts": { | |
"start": "http-server" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"express": "^4.18.2", | |
"open": "^10.0.3", | |
"path": "^0.12.7" | |
}, | |
"devDependencies": { | |
"@types/express": "^4.17.21" | |
} | |
} | |
*/ | |
const open = require("open"); | |
// Listen on a specific host via the HOST environment variable | |
var host = process.env.HOST || "localhost"; | |
// Listen on a specific port via the PORT environment variable | |
var port = process.env.PORT || 8080; | |
const express = require ("express"); | |
const join = require ("path"); | |
const app = express(); | |
var dir = "/"; | |
var index = "index.html"; | |
app.use(express.static(__dirname + dir)); | |
// sendFile will go here | |
app.get("/", function (req, res) { | |
res.sendFile(join(dir, index)); | |
}); | |
app.listen(port, host, function () { | |
console.log("http://" + host + ":" + dir + index); | |
open("http://" + host + ":" + port + "/" + index, { app: "chrome" }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment