-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
20 lines (15 loc) · 730 Bytes
/
server.js
File metadata and controls
20 lines (15 loc) · 730 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// server.js
const jsonServer = require("json-server");
const path = require("path");
const server = jsonServer.create(); // Create a JSON Server instance
const dbFile = path.join(__dirname, "./fixtures/db.json"); // Construct the path to the db.json file
const router = jsonServer.router(dbFile); // Create a router using the db.json file
const middlewares = jsonServer.defaults();
const port = process.env.PORT || 3000; // set the port you want, here 3000 as json-server
server.use(middlewares);
server.use("/api/", router);
server.use(jsonServer.bodyParser);
// Start the server and listen on the specified port
server.listen(port, () => {
console.log(`MOCK-API is running on: http://localhost:${port}/api/pizzas`);
});