无法在 firebase 函数模拟器上提供 express 应用程序 | EADDRINUSE:地址已在使用中::::3000
Can't serve express app on firebase functions emulator | EADDRINUSE: address already in use :::3000
我正在使用 firebase 函数在 firebase 上测试快速应用程序部署。
但是在使用命令firebase serve
之后。我得到 EADDRINUSE: address already in use :::3000
。这是我的 index.js
const functions = require('firebase-functions');
const express = require('express');
const validator = require('email-validator');
const PORT = 3000;
const app = express();
/* JSON body parse*/
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.get('/hello', (req, res, next) => {
console.info('/hello call success ');
res.send('Welcome to Firebase Cloud Functions');
});
app.post('/emailValidate', async (req, res, next) => {
const postData = req.body;
if (postData.email) {
console.info('/emailValidate call success ');
res.json({ 'status': validator.validate(postData.email) });
} else {
console.warn('/emailValidate wrong input ');
res.status(500).json({ 'status': 'wrong input' });
}
});
app.listen(PORT, () => {
console.info('Server is running on PORT:', PORT);
});
exports.app = functions.https.onRequest(app);
package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "index.js",
"dependencies": {
"body-parser": "^1.19.1",
"email-validator": "^2.0.4",
"express": "^4.17.2",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}
打开时出错 URL functions[us-central1-app]: http function initialized (http://localhost:5001/{app-name}/us-central1/app).
node:events:368
> throw er; // Unhandled 'error' event
> ^
>
> Error: listen EADDRINUSE: address already in use :::3000
> at Server.setupListenHandle [as _listen2] (node:net:1334:16)
> at listenInCluster (node:net:1382:12)
> at Server.listen (node:net:1469:7)
> at Function.listen (\home\development\express-firebase\functions\node_modules\express\lib\application.js:618:24)
> at Object.<anonymous> (D:[=12=]2_Research_Development\Web\development\express-firebase\functions\index.js:29:5)
> at Module._compile (node:internal/modules/cjs/loader:1101:14)
> at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
> at Module.load (node:internal/modules/cjs/loader:981:32)
> at Function.Module._load (node:internal/modules/cjs/loader:822:12)
> at Module.require (node:internal/modules/cjs/loader:1005:19)
> Emitted 'error' event on Server instance at:
> at emitErrorNT (node:net:1361:8)
> at processTicksAndRejections (node:internal/process/task_queues:83:21) {
> code: 'EADDRINUSE',
> errno: -4091,
> syscall: 'listen',
> address: '::',
> port: 3000
> }
此外,我已经检查过在定义的端口上已经没有任何东西 运行。甚至尝试更改 index.js
中的端口号,但问题仍然存在。
如有任何帮助,我们将不胜感激。 :)
另一个应用程序正在使用端口 3000,您需要停止该应用程序and/or 终止端口,具体取决于您的操作系统。
我正在使用 firebase 函数在 firebase 上测试快速应用程序部署。
但是在使用命令firebase serve
之后。我得到 EADDRINUSE: address already in use :::3000
。这是我的 index.js
const functions = require('firebase-functions');
const express = require('express');
const validator = require('email-validator');
const PORT = 3000;
const app = express();
/* JSON body parse*/
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.get('/hello', (req, res, next) => {
console.info('/hello call success ');
res.send('Welcome to Firebase Cloud Functions');
});
app.post('/emailValidate', async (req, res, next) => {
const postData = req.body;
if (postData.email) {
console.info('/emailValidate call success ');
res.json({ 'status': validator.validate(postData.email) });
} else {
console.warn('/emailValidate wrong input ');
res.status(500).json({ 'status': 'wrong input' });
}
});
app.listen(PORT, () => {
console.info('Server is running on PORT:', PORT);
});
exports.app = functions.https.onRequest(app);
package.json
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "16"
},
"main": "index.js",
"dependencies": {
"body-parser": "^1.19.1",
"email-validator": "^2.0.4",
"express": "^4.17.2",
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1"
},
"devDependencies": {
"firebase-functions-test": "^0.2.0"
},
"private": true
}
打开时出错 URL functions[us-central1-app]: http function initialized (http://localhost:5001/{app-name}/us-central1/app).
node:events:368
> throw er; // Unhandled 'error' event
> ^
>
> Error: listen EADDRINUSE: address already in use :::3000
> at Server.setupListenHandle [as _listen2] (node:net:1334:16)
> at listenInCluster (node:net:1382:12)
> at Server.listen (node:net:1469:7)
> at Function.listen (\home\development\express-firebase\functions\node_modules\express\lib\application.js:618:24)
> at Object.<anonymous> (D:[=12=]2_Research_Development\Web\development\express-firebase\functions\index.js:29:5)
> at Module._compile (node:internal/modules/cjs/loader:1101:14)
> at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
> at Module.load (node:internal/modules/cjs/loader:981:32)
> at Function.Module._load (node:internal/modules/cjs/loader:822:12)
> at Module.require (node:internal/modules/cjs/loader:1005:19)
> Emitted 'error' event on Server instance at:
> at emitErrorNT (node:net:1361:8)
> at processTicksAndRejections (node:internal/process/task_queues:83:21) {
> code: 'EADDRINUSE',
> errno: -4091,
> syscall: 'listen',
> address: '::',
> port: 3000
> }
此外,我已经检查过在定义的端口上已经没有任何东西 运行。甚至尝试更改 index.js
中的端口号,但问题仍然存在。
如有任何帮助,我们将不胜感激。 :)
另一个应用程序正在使用端口 3000,您需要停止该应用程序and/or 终止端口,具体取决于您的操作系统。