Last active
July 7, 2020 06:11
-
-
Save sijeesh-02/d773d3b0b6e2c175a1c0b350ee43a370 to your computer and use it in GitHub Desktop.
Express file for basic server, created for blog post
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
const express = require("express"); | |
const app = express(); | |
const path = require("path"); | |
const config = { | |
port: 3000, | |
}; | |
/** | |
* all calls to /assets would be taken from | |
* a new path which is join of current directory (__dirname) | |
* and | |
* ../../dist/ui (root/dist/ui) | |
*/ | |
app.use("/assets", express.static(path.join(__dirname, "../../dist/ui"))); | |
/** | |
* All calls to express server on path / will serve index.html | |
* from path root/public | |
*/ | |
app.get("/", (req, res) => { | |
res.sendFile(path.join(__dirname, "../../public", "index.html")); | |
}); | |
app.listen(config.port, () => | |
console.log(`Example app listening at http://localhost:${config.port}`) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment