Created
April 4, 2022 17:03
-
-
Save sagar-barapatre/20eea151cc2f3b9d222152c7248200ad to your computer and use it in GitHub Desktop.
Setup a Nodejs Backend
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 app = express(); | |
require("dotenv").config(); | |
const mongoose = require("mongoose"); | |
const user = require("./models/user"); | |
app.use(express.json()); | |
app.use(express.urlencoded({ extended: true })); | |
mongoose.connect(process.env.MONGODB_URI, { | |
useNewUrlParser: true, | |
}); | |
let db = mongoose.connection; | |
db.once("open", () => console.log("MongoDB connected Successfully!")); | |
db.on("error", console.error.bind(console, "MongoDB connection error:")); | |
const PORT = process.env.PORT; | |
app.listen(PORT, () => { | |
console.log(`Server is listening on port ${PORT}`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment