【问题标题】:I am confuse , I started my server on port 50001 but my react app is running on 3000 port what is problem ? Plz help me Thanks我很困惑,我在端口 50001 上启动了我的服务器,但我的反应应用程序在 3000 端口上运行有什么问题?请帮助我谢谢
【发布时间】:2022-12-22 04:17:37
【问题描述】:

这是我的服务器 mjs 文件:

import Express from "express";
const port = process.env.PORT || 50001;
const app = Express();
import path from 'path'


app.get('/abc',(req,res) => {
    console.log("Resquest ip ",req.ip);
    res.send("Hello World Node js is here");

})

app.get('/application',(req,res) => {
    console.log("Resquest ip ",req.ip);
    res.send("Hello World Node js is here");

})

app.get('/kiet',(req,res) => {
    console.log("Resquest ip ",req.ip);
    res.send("Hello World Node js is here");

})

app.get('/computer',(req,res) => {
    console.log("Resquest ip ",req.ip);
    res.send("Hello World Node js is here");

})
const __dirname = path.resolve();
app.use('*',Express.static(path.join(__dirname,'./web/build')))

app.listen(port,()=>{
    console.log("App listening on port ",port)
})

或者你可以看到我的node js和React的运行命令

enter image description here

Plz hepl 谢谢:

错误在哪里?帮我。谢谢

【问题讨论】:

    标签: node.js reactjs express server node-modules


    【解决方案1】:

    因为那是两个独立的应用程序。你在 50001 上运行你的 express 并且它很好但是反应使用反应脚本在本地主机上为你的反应应用程序提供服务并使用 3000 端口作为默认端口。

    【讨论】:

    • 但是小弟反应app在node js server中。
    • 你是什​​么意思它在 nodejs 服务器中?
    猜你喜欢
    • 2020-10-27
    • 2018-07-19
    • 1970-01-01
    • 2012-01-17
    • 2021-12-28
    • 2014-11-18
    • 2010-09-27
    • 2016-08-17
    • 2022-12-20
    相关资源
    最近更新 更多