-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
23 lines (19 loc) · 761 Bytes
/
server.js
File metadata and controls
23 lines (19 loc) · 761 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const express = require('express');
const apiRoute = require('./routes/apiRoutes');
const htmlRoute = require('./routes/htmlRoutes');
// const path = require('path');
const PORT = process.env.PORT || 3001;
const app = express();
// Need access to the public Folder before routes
// Invoking app.use() and serve static files from the '/public' folder
app.use(express.static('public'));
// DIDN'T WORK -> app.use(express.static(path.join(__dirname, 'public')));
// Middleware for parsing JSON and urlencoded form data
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/api', apiRoute);
app.use('/', htmlRoute);
// Listen for connections
app.listen(PORT, () =>
console.log(`App listening at http://localhost:${PORT} 🚀`)
);