-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathserver.js
More file actions
21 lines (18 loc) · 852 Bytes
/
server.js
File metadata and controls
21 lines (18 loc) · 852 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* Server.js will define the properties of the application - express application using JSON, base URL for requests*/
/* Import dependencies */
import express from 'express'
import router from './routes.js'
/* This app will be an express server*/
const app = express();
const port = 5000;
/* Set server properties - cross origin sharing, express.json, base url, invalid url handling - return 404 error */
app.use(express.json());
/* requests to '/api' requests will be routed to the routes.js sibling file */
app.use("/api", router);
app.use("*", (req, res) => {res.status(404).json({error : 'page does not exist'})});
/* app.use("/*", (req, res) => {res.status(404).json({error : "Page does not exist"})});
*/
/* Activate the server to listen for requests */
app.listen(port,()=>{
console.log(`server waiting for requests on port ${port}`)
});