General Express Server API with TypeScript

PHOTO EMBED

Sun Nov 22 2020 16:49:47 GMT+0000 (UTC)

Saved by @narro #typescript #nodejs

const port = process.env.PORT || 3000;

import express from "express";
import path from "path";
import bodyParser from "body-parser";
import cors from "cors";
const app = express();

app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(cors());

//* Root Handler
app.get("/", (req, res) =>
  res.sendFile(path.join(__dirname + "/public/index.html"))
);

app.get('api/v1', (req,res) => res.json())

// Set static folder
app.use(express.static(path.join(__dirname, 'public')));

app.use('/api/v1', require('./routes/api/v1'))

app.listen(port, () => {
  console.log(`Server at: http://localhost:${port}`);
});
content_copyCOPY

NodeJS - loosely based on my DebtCollect.io server

debtcollect.io