Created
July 5, 2021 11:35
-
-
Save pprathameshmore/c1bc0b9fd35d47e1f29221d95fce4c6c to your computer and use it in GitHub Desktop.
This file contains 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
import { config } from "dotenv"; | |
config(); | |
import http from "http"; | |
import express, { Request, Response } from "express"; | |
import { Server } from "socket.io"; | |
import mongoose from "mongoose"; | |
import cors from "cors"; | |
import path from "path"; | |
import morgan from "morgan"; | |
import { SocketInit } from "./socket.io"; | |
import { downloadsRouter } from "./routes/downloads"; | |
const app = express(); | |
const server = http.createServer(app); | |
export const io = new Server(server, { | |
cors: { origin: "*" }, | |
}); | |
new SocketInit(io); | |
mongoose | |
.connect(process.env.MONGO_DB, { | |
useNewUrlParser: true, | |
useUnifiedTopology: true, | |
}) | |
.then(() => { | |
console.log("Connected to database"); | |
}) | |
.catch((error) => { | |
throw error; | |
}); | |
app.use(morgan("dev")); | |
app.use(express.json()); | |
app.use(express.urlencoded({ extended: true })); | |
app.set("view engine", "ejs"); | |
app.use(express.static(path.join(__dirname, "views"))); | |
app.use(cors()); | |
app.use(downloadsRouter); | |
app.get("/", (req: Request, res: Response) => { | |
res.render("index"); | |
}); | |
server.listen(3000, () => { | |
console.log("Server running up 3000"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment