我正在尝试使用 WSL2、Docker Desktop 和 Lando(通过 WSL2 安装)在 Windows 10 上开始构建 Express/Node/React 应用程序,但在运行基本的 Express 部分时遇到问题。
根据 Google 搜索,它似乎很可能与 Windows 相关。我没有太多在 Windows 上开发的经验,通常使用 Linux 发行版或 macOS。
- 操作系统:Windows 10
- wsl:Ubuntu 20.04
- 兰多:3.6.0
- 码头工人桌面:4.5.0
- 节点:v16.14.0
- npm:8.5.0
这是我的/app/server/index.js
:
const express = require('express');
const app = express();
app.listen('/', (req, res) => {
res.send({ foo: 'bar' });
});
app.listen(5000);
这是我的.lando.yml
:
name: test
recipe: mean
config:
node: 16
build:
- npm install -g npm
# command: npm start
database: mongo:5.0
globals: []
# gulp-cli: latest
port: 80
ssl: false
proxy:
appserver:
- server.test.lndo.site:5000
运行时:
lando node index.js
我收到此错误:listen EADDRINUSE: address already in use
node:events:498
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE: address already in use /
at Server.setupListenHandle [as _listen2] (node:net:1313:21)
at listenInCluster (node:net:1378:12)
at Server.listen (node:net:1476:5)
at Function.listen (/app/server/node_modules/express/lib/application.js:618:24)
at Object.<anonymous> (/app/server/index.js:4:5)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
Emitted 'error' event on Server instance at:
at emitErrorNT (node:net:1357:8)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
code: 'EADDRINUSE',
errno: -98,
syscall: 'listen',
address: '/',
port: -1
}
切换路径app.listen()
只会导致相同的错误。