-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8900ac7
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
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
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") | ||
}) | ||
|