Javascript sendFile不是基于express的节点应用程序中的函数?
我在Javascript sendFile不是基于express的节点应用程序中的函数?,javascript,node.js,express,filepath,Javascript,Node.js,Express,Filepath,我在server.js(其中app是一个express实例)中有以下代码,它应该返回一个文件index.html,该文件与server.js位于同一目录中 app.get('/', function (req, res) { var indexPath = path.resolve('index.html'); res.sendFile(indexPath); }); 我注销了indepath,它是我的html文件的正确路径。但是我得到了以下错误 TypeError:res.s
server.js
(其中app是一个express实例)中有以下代码,它应该返回一个文件index.html
,该文件与server.js
位于同一目录中
app.get('/', function (req, res) {
var indexPath = path.resolve('index.html');
res.sendFile(indexPath);
});
我注销了indepath
,它是我的html文件的正确路径。但是我得到了以下错误
TypeError:res.sendFile不是函数
和调用跟踪:
在早期版本的Express中,使用的方法是
senfile
,而不是sendFile
更新到,您将能够使用sendFile
。4.14也是一个安全更新,因此强烈建议使用
您可以将其添加到
包.json
文件中:“express”:“^4.14.0”
在早期版本的express中,使用的方法是senfile
,而不是sendFile
更新到,您将能够使用sendFile
。4.14也是一个安全更新,因此强烈建议使用
您可以将其添加到您的
包.json文件中:“express”:“^4.14.0”
您使用的express版本是什么?我使用的版本是^4确切的版本是什么sendFile
仅在4.8.0+版本中可用,我不确定。我的包文件有“express”:“^4”,
,我是否应该改为指定类似于4.8.0+的内容?请执行npm list
并查看您获得的版本。如果您需要4.8.0+版本,请执行^4.8.0
您使用的Express版本是什么?我使用的版本是^4确切的版本是什么sendFile
仅在4.8.0+版本中可用,我不确定。我的包文件有“express”:“^4”,
,我是否应该改为指定类似于4.8.0+的内容?请执行npm list
并查看您获得的版本。如果您需要4.8.0+版本,请执行^4.8.0
at Object.handle (/Users/alexanderbollbach/Desktop/ABApp/server.js:54:9)
at next_layer (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/route.js:103:13)
at Route.dispatch (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/route.js:107:5)
at /Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:195:24
at Function.proto.process_params (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:251:12)
at next (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:189:19)
at Layer.jsonParser [as handle] (/Users/alexanderbollbach/Desktop/ABApp/node_modules/body-parser/index.js:31:38)
at trim_prefix (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:226:17)
at /Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:198:9
at Function.proto.process_params (/Users/alexanderbollbach/Desktop/ABApp/node_modules/express/lib/router/index.js:251:12)