-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
36 lines (29 loc) · 888 Bytes
/
server.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
33
34
35
36
import express from 'express';
import nunjucks from 'nunjucks';
import { config } from 'dotenv';
import path, { dirname } from 'path';
import { fileURLToPath } from 'url';
import routes from './routes/index.js';
// Load environment variables
config({ path: './.env' });
// Initialize Express app
const app = express();
const __dirname = dirname(fileURLToPath(import.meta.url));
// Middleware
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
// Configure Nunjucks
nunjucks.configure('views', {
autoescape: true,
express: app,
});
// Set default view engine to 'njk'
app.set('view engine', 'njk');
// Use modularized routes
app.use('/', routes);
// Start server
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});