Skip to content

Commit 6c3fa66

Browse files
committedFeb 29, 2020
init
0 parents  commit 6c3fa66

File tree

3,218 files changed

+391321
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,218 files changed

+391321
-0
lines changed
 

‎.env

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
URI=mongodb+srv://jaffer:password110@nodeapi-al9by.mongodb.net/test?retryWrites=true&w=majority
2+
port=8001
3+
JWT_SECRET=EWT1WEF4DS9HER79URE9SF4SA

‎app.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const express = require("express");
2+
const connectDb = require("./connect");
3+
const app = express();
4+
const expressValidator = require("express-validator");
5+
const bodyParser = require("body-parser");
6+
const cookieParser = require("cookie-parser");
7+
const dotenv = require("dotenv");
8+
9+
connectDb();
10+
dotenv.config();
11+
12+
// bring in routes
13+
const postRoutes = require("./routes/post.js");
14+
const authRoutes = require("./routes/auth.js");
15+
const userRoutes = require("./routes/user.js");
16+
17+
//middleware
18+
app.use(bodyParser.json());
19+
app.use(cookieParser());
20+
app.use("/", postRoutes);
21+
app.use("/", authRoutes);
22+
app.use("/", userRoutes);
23+
app.use(function(err, req, res, next) {
24+
if (err.name === "UnauthorizedError")
25+
res.status(401).json({ error: "Unauthorized!" });
26+
});
27+
28+
const port = process.env.PORT || 8001;
29+
app.listen(port, () => {
30+
console.log(`A node JS API is Listening on port : ${port}`);
31+
});

0 commit comments

Comments
 (0)