路由页面错误代码时出错:错误:ENOENT,stat'/public/index.html'使用节点

时间:2022-10-12 20:56:45

I use This code :

我用这段代码:

var express = require("express");
var path =  require("path");
var app =  express();
app.use(express.static(path.join(__dirname, 'public')));
app.use("/",function(req,res){
    res.sendfile('/public/index.html');
  //res.send("test");
}),
app.listen(5401)

It working fine when I Enter url On Browser. shown in pic.

我在浏览器上输入url时工作正常。如图所示。

路由页面错误代码时出错:错误:ENOENT,stat'/public/index.html'使用节点

but in terminal i always getting en error :ENOENT, stat '/public/index.html' I don't know what is my mistake and i am using emberjs on client side

但在终端我总是得到错误:ENOENT,stat'/public/index.html'我不知道我的错误是什么,我在客户端使用emberjs

1 个解决方案

#1


2  

Try using:

var express = require("express");
var path =  require("path");
var app =  express();
app.use(express.static(path.join(__dirname, 'public')));
app.use("/",function(req,res){
    res.sendfile(path.join(__dirname, '../public', 'index.html'));
  //res.send("test");
}),
app.listen(5401);

#1


2  

Try using:

var express = require("express");
var path =  require("path");
var app =  express();
app.use(express.static(path.join(__dirname, 'public')));
app.use("/",function(req,res){
    res.sendfile(path.join(__dirname, '../public', 'index.html'));
  //res.send("test");
}),
app.listen(5401);