简体   繁体   English

express.js中sendFile HTML文件中的错误

[英]error in sendFile HTML file in express.js

I am triying yo show a file HTML with expressjs with a static __dirname but doasnt show the html after calling localhost/ 我正在尝试用静态__dirname显示带有expressjs的文件HTML,但是在调用localhost /之后不显示html

 var express= require('express'); var web=express(); web.use(express.static(__dirname+'/shalimar')); //Inside /shalimar is located 'home.html' web.get('/',(req,res)=>{ console.log("Estoy Cargando desde '/'"); res.sendFile('home.html'); }); web.listen(4200,function(){ console.log('Servidor Web Iniciado en el Puerto : 4200') }); 

the console show e this error 控制台显示此错误

TypeError: path must be absolute or specify root to res.sendFile

How is the correct way to send an html file to local side? 如何将html文件发送到本地的正确方法?

According the doc : 根据文档

Unless the root option is set in the options object, path must be an absolute path to the file. 除非在options对象中设置了root选项,否则path必须是文件的绝对路径。

the root option can be set in the second param: root选项可以在第二个参数中设置:

res.sendFile(path [, options] [, fn])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM