首页 > 解决方案 > 没有这样的文件或目录,stat 'C:\idora-photobok\backend\frontend\build\index.html'

问题描述

因此,在尝试准备我的应用程序进行生产时出现此错误。所以,我的 index.js 代码是

const app = express();
const port = 8000;
const cors = require('cors');
const db=require('./config/mongoose');
const path = require('path')

//library used
const passport = require('passport');
const passportJWT = require('./config/passport-jwt-strategy');
const bcrypt = require('bcrypt');



//middleware
app.use(express.json());
app.use(cors());
//use routes
app.use('/', require('./routes'));

app.use(express.static(path.join(__dirname, '/frontend/build')))

app.get('*', (req, res) => 
  res.sendFile(path.join(__dirname, 'frontend', 'build', 'index.html')))

app.listen(port, async function(err){
    if(err){
        console.log(`error in running of server;${err}`);
    }
  console.log(`server is running on port:${port}`);
    });

在此处输入图像描述

这是我的文件结构。所以,如果有人知道,为什么会这样。请回复。

谢谢

标签: javascriptnode.jsreactjsexpress

解决方案


推荐阅读