这是我的index.js文件:
const express = require('express')
const app = express()
app.set('views', __dirname + '/views');
app.set('view engine', 'pug')
app.get('/', function (req, res) {
res.render('index', { title: 'Hey', message: 'Hello there!' })
})
app.listen(3333, function () {
console.log('Example app listening on port 3333!')
})
index.pug 文件:
html
head
title= title
body
h1= Hello
package.json 文件:
{
"name": "@npm-private/pug_with_node",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.3",
"jade": "^1.11.0",
"pug": "^2.0.0-rc.2"
}
}
当我运行我的服务器文件时,它显示了一个错误。事实上,我安装了pug和jade两个npm模块:
Error: 找不到模块 'pug' at Function.Module._resolveFilename (module.js:485:15) at Function.Module._load (module.js:437:25) at Module.require (module.js:513:17) at require (internal/module.js:11:18) at new View (/home/software/node_modules/express/lib/view.js:80:30) at Function.render (/home/software/node_modules/express/lib/application.js:570:12) at ServerResponse.render (/home/software/node_modules/express/lib/response.js:971:7) at /home/software/Harsh Patel/pug_with_node/index.js:8:7 at Layer.handle [as handle_request] (/home/software/node_modules/express/lib/router/layer.js:95:5) at next (/home/software/node_modules/express/lib/router/route.js:137:13)
pug
。 - Ved