[英]Can't serve express app on firebase functions emulator | EADDRINUSE: address already in use :::3000
I am testing express app deployment on firebase using firebase functions.我正在使用 firebase 函数在 firebase 上测试快速应用程序部署。 But after using the command
firebase serve
.但是在使用命令
firebase serve
之后。 I am getting EADDRINUSE: address already in use:::3000
.我得到
EADDRINUSE: address already in use:::3000
。 Here is my index.js这是我的 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 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
}
Error while opening URL functions[us-central1-app]: http function initialized (http://localhost:5001/{app-name}/us-central1/app).
打开 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:\002_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
> }
Also, I have checked already there was nothing running at the defined PORT.另外,我已经检查了在定义的端口上没有运行任何东西。 Even tried changing the PORT number in
index.js
but the issue persist.甚至尝试更改
index.js
中的端口号,但问题仍然存在。
Any help would be much appreciated.任何帮助将非常感激。 :)
:)
Another application is using port 3000, you need to stop the application and/or kill the port which varies depending on your operating system.另一个应用程序正在使用端口 3000,您需要停止该应用程序和/或终止该端口,具体取决于您的操作系统。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.