Skip to content

Instantly share code, notes, and snippets.

@agrcrobles
Created October 29, 2018 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrcrobles/f3eeb8b7d5cf591219475e6bfda3d8d4 to your computer and use it in GitHub Desktop.
Save agrcrobles/f3eeb8b7d5cf591219475e6bfda3d8d4 to your computer and use it in GitHub Desktop.
express simple server

Simple Server in Express

  1. Fix the route when necessary

  2. Run

npm init
yarn add express
node index.js
const path = require("path");
const express = require("express");
const app = express();
const PORT = process.env.PORT || 3000;
app.use(express.static(path.join(__dirname, "..", "build")));
app.get("/*", function(req, res) {
res.sendFile(
path.join(__dirname, __dirname, "..", "build", "index.html")
);
});
app.listen(PORT, (req, res) => {
console.log(`The server is up on port ${PORT}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment