Issue
I am testing express app deployment on firebase using firebase functions.
But after using the command firebase serve
. I am getting EADDRINUSE: address already in use :::3000
. Here is my 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
}
Error while opening 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.
Any help would be much appreciated. 🙂
Solution
Another application is using port 3000, you need to stop the application and/or kill the port which varies depending on your operating system.
Answered By – destroyer22719
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0