Skip to content

Commit

Permalink
Create index.js
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilpal755 authored Sep 18, 2021
0 parents commit 8900ac7
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import express from "express";
import mongoose from "mongoose";
import dotenv from "dotenv";
import helmet from "helmet";
import morgan from "morgan";
import Users from './routes/users.js';
import Auth from "./routes/auth.js";
import Posts from "./routes/posts.js";


const app = express();
const port = process.env.PORT || 3000;
app.listen(port , () => console.log("app is running"));


// loading a .env file
dotenv.config();


// connection to mongoDB atlas
mongoose.connect(process.env.MONGO_URL , {useNewUrlParser : true, useUnifiedTopology : true})
.then( () => console.log("connected to mongo Atlas"))
.catch((err) => console.log(err));

// middlewares
app.use(express.json());
app.use(helmet());
app.use(morgan('common'));
app.use("/api/users" , Users );
app.use("/api/auth" , Auth);
app.use("/api/posts", Posts);


app.get("/" , (req, res) =>{
res.send("Root route of app")
})

0 comments on commit 8900ac7

Please sign in to comment.