Skip to content

Instantly share code, notes, and snippets.

@WoolDoughnut310
Created October 28, 2022 14:54
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 WoolDoughnut310/0168138d3b01f35b52ddf7705acde44e to your computer and use it in GitHub Desktop.
Save WoolDoughnut310/0168138d3b01f35b52ddf7705acde44e to your computer and use it in GitHub Desktop.
import dotenv from "dotenv";
dotenv.config();
import express, { Request, Response } from "express";
import { connectToServer } from "./db";
const app = express();
const port = 3000;
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.get("/", (req, res) => {
res.send("Hello World!");
});
app.use((err: Error, req: Request, res: Response) => {
res.status(500).json({ message: err.message });
});
connectToServer().then(async () => {
app.listen(port, () => {
return console.log(`Express is listening at http://localhost:${port}`);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment