Last active
November 19, 2020 17:34
-
-
Save TheArhaam/68f9643ca6c8b5c83e4fb315868a6977 to your computer and use it in GitHub Desktop.
randomlist server.js
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
const express = require("express"); | |
const mongoose = require("mongoose"); | |
const cors = require("cors"); | |
const app = express(); | |
require("dotenv").config(); | |
app.use(cors()); | |
app.use(express.json()); | |
// MONGODB CONNECTION | |
mongoose.connect( | |
process.env.MONGODB_URI, | |
{ | |
useNewUrlParser: true, | |
useCreateIndex: true, | |
useUnifiedTopology: true | |
} | |
); | |
const connection = mongoose.connection; | |
connection.once("open", () => { | |
console.log("MongoDB connection established successfully!"); | |
}); | |
// ROUTES | |
const listRouter = require("./routes/api/list"); | |
app.use('/list', listRouter); | |
app.listen(process.env.PORT, () => { | |
console.log("Server is running on port:" + process.env.PORT); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment