After importing the expressEdge I got stucked.
const path =require('path');
const expressEdge = require('express-edge');
const express = require('express');
const app = new express();
app.use(express.static('public'));
app.use(expressEdge);
app.set("views", `${__dirname}/views`);
app.get('/', (req, res) => {
res.render('index')
})
app.get('/about.html', (req, res) => {
res.sendFile(path.resolve(__dirname, 'pages/about.html'));
})
app.get('/contact.html', (req, res) => {
res.sendFile(path.resolve(__dirname, 'pages/contact.html'));
})
app.get('/post', (req, res) => {
res.sendFile(path.resolve(__dirname, 'pages/post.html'));
})
app.listen(5000, () => {
console.log('App listening o port 5000');
})
while trying to introduce the expressEdge I got these error below:
at Object.<anonymous> (C:\Users\Globalwise\Desktop\nodejs-blog\index.js:11:5)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
at Function.Module._load (internal/modules/cjs/loader.js:531:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
[nodemon] app crashed - waiting for file changes before starting...
Your help would be appreciated.
Thanks all in advance.
When you
require('express-edge
), it brings in an object. When you register the middleware you need to pass theengine
. You have two options...Access the
engine
property from the required objectOr access the
engine
property on therequire