我的Express应用程序在推送到我的Tessel 2上时出现了问题,我可以在本地运行它,但一旦它被推送到另一个系统上,就会导致问题。这是我得到的错误:
Error: ENOENT: no such file or directory, stat '/tmp/remote-script/public/index.html'
at Error (native)这是我的Express路由设置:
app.use('/static', express.static('public'))
app.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/public/index.html'));
})我尝试了几个不同的文件路径位置,比如/../public/index.html,但似乎都不起作用。我的目录结构将index.js作为主节点文件,然后我有一个公共目录,其中包含index.html文件。
任何帮助都将不胜感激。
发布于 2017-08-04 00:29:20
这最终成为了Tessel 2的问题,而不是Node,我需要更新.tesselinclude文件来将公共目录推送到设备上,如下所示:public/**
发布于 2017-07-31 02:20:27
尝试在express.static中使用绝对路径
app.use('/static', express.static(path.join(__dirname, 'public')))然后
res.sendFile(path.join(__dirname, '/public/index.html'));另外,我建议您使用render而不是上面的代码
res.render('index')https://stackoverflow.com/questions/45403029
复制相似问题