-
Notifications
You must be signed in to change notification settings - Fork 0
/
express.js
43 lines (37 loc) · 1.17 KB
/
express.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
37
38
39
40
41
42
43
import express from 'express';
import exphbs from 'express-handlebars';
import alpineHbsHelpers from './helpers/alpine-hbs-helpers.js';
// __dirname for ES:
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const app = express();
const port = 3000;
const hbs = exphbs.create({
viewsDir: path.join(__dirname, 'views'),
layoutsDir: path.join(__dirname, 'views/layouts'),
partialsDir: path.join(__dirname, 'views/partials'),
//extname: '.hbs', //You can specify additional extensions
//helpers: {} // Your existing custom helpers can go here
});
// Register the Alpine.js plugin
alpineHbsHelpers(hbs.handlebars);
app.engine('.hbs', hbs.engine);
app.set('view engine', '.hbs');
//app.set('views', path.join(__dirname, 'views'));
app.get('/', (req, res) => {
res.render('index', {
title: 'Home Page',
alpineData: {
count: 0,
message: "Welcome to Alpine.js with Handlebars!",
todos: [],
newTodo: '',
selectedTodo: '',
fetchedData: ''
}});
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});