-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (24 loc) · 773 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* NodeJS-MongoDB RestAPI example */
/* By Mayank Choudhary */
import express from "express";
import bodyParser from "body-parser";
import "./database/connection.js";
import Routes from "./routes/users.js";
import Path from "path";
// express
const app = express();
const PORT = 5000; // Port where our server will run!
const ROOT_DIRECTORY = Path.resolve(); // to get the root
// add css directory
app.use(express.static(Path.join(ROOT_DIRECTORY, 'styles')));
// parse to json
app.use(bodyParser.json());
// route for users API
app.use("/users", Routes);
// default route for API
app.get("/", (req, res) => {
res.sendFile(Path.join(ROOT_DIRECTORY, "/index.html"));
});
app.listen(PORT, () => {
console.log(`Server is running at http://localhost:${PORT}`);
});