Skip to content

Instantly share code, notes, and snippets.

@sagar-barapatre
Created April 4, 2022 17:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagar-barapatre/20eea151cc2f3b9d222152c7248200ad to your computer and use it in GitHub Desktop.
Save sagar-barapatre/20eea151cc2f3b9d222152c7248200ad to your computer and use it in GitHub Desktop.
Setup a Nodejs Backend
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