Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript sendFile不是基于express的节点应用程序中的函数?_Javascript_Node.js_Express_Filepath - Fatal编程技术网

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)