在使用res.sendFile('test.html')的时候会抛出错误提示:

node.js关于sendFile的路径问题

解决办法是:res.sendFile(path.join(__dirname, '../public/html', 'test.html'));

其中app.js的静态文件路由是:app.use(express.static(path.join(__dirname, '/public')));

当加载外部html页面后如果引用外部css样式,改为:../stylesheets/style.css即可实现。

文件截图如下:

node.js关于sendFile的路径问题

相关文章:

  • 2021-12-06
  • 2022-01-21
  • 2021-04-10
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
猜你喜欢
  • 2022-12-23
  • 2021-07-17
  • 2022-12-23
  • 2021-12-06
  • 2022-12-23
  • 2022-02-15
  • 2021-10-23
相关资源
相似解决方案