-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
26 lines (20 loc) · 654 Bytes
/
Copy pathapp.js
File metadata and controls
26 lines (20 loc) · 654 Bytes
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
const express = require('express');
const path = require('path');
const indexRouter = require('./routes/index');
const app = express();
const port = 3000;
// Middleware to serve static files
app.use(express.static(path.join(__dirname, 'public')));
// Middleware for parsing JSON and urlencoded data
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
// Use the routes
app.use('/', indexRouter);
// Error handling middleware
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('Something broke!');
});
app.listen(port, () => {
console.log(`App listening at http://localhost:${port}`);
});