0

导入 expressEdge 后,我被卡住了。

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');
})

在尝试介绍 expressEdge 时,出现以下错误:

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] 应用程序崩溃 - 启动前等待文件更改...

您的帮助将不胜感激。

提前谢谢大家。

4

1 回答 1

0

当你require('express-edge) 时,它会引入一个对象。当您注册中间件时,您需要通过engine. 你有两个选择...

engine从所需对象访问属性

const expressEdge = require('express-edge');
app.use(expressEdge.engine);

或访问该engine属性require

const expressEdgeEngine = require('express-edge').engine;
app.use(expressEdgeEngine);

https://www.npmjs.com/package/express-edge

于 2020-04-09T15:03:11.843 回答