Skip to content

Instantly share code, notes, and snippets.

@TheArhaam
Last active November 19, 2020 17:34
Show Gist options
  • Save TheArhaam/68f9643ca6c8b5c83e4fb315868a6977 to your computer and use it in GitHub Desktop.
Save TheArhaam/68f9643ca6c8b5c83e4fb315868a6977 to your computer and use it in GitHub Desktop.
randomlist server.js
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