/Users/jake/.pm2/logs/main-error.log last 15 lines:
0|main | at listenInCluster (net.js:1356:12)
0|main | at Server.listen (net.js:1444:7)
0|main | at Object.<anonymous> (/Users/jake/Desktop/Nodejs-master/main.js:143:5)
0|main | at Module._compile (internal/modules/cjs/loader.js:1139:30)
0|main | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1159:10)
0|main | at Module.load (internal/modules/cjs/loader.js:988:32)
0|main | at Function.Module._load (internal/modules/cjs/loader.js:896:14)
0|main | at Object.<anonymous> (/usr/local/lib/node_modules/pm2/lib/ProcessContainerFork.js:32:23)
0|main | at Module._compile (internal/modules/cjs/loader.js:1139:30) {
0|main | code: 'EADDRINUSE',
0|main | errno: -48,
0|main | syscall: 'listen',
0|main | address: '::',
0|main | port: 3000
0|main | }
pm2 start main.js --watch works but when i try pm2 logs i got above error
anyone please help to fix this error thanks
EADDRINUSE means this port is already being used by some other application. Maybe a node is already running on this port.
First, run sudo pkill -9 node and use pm2. If this doesn't solve your problem, then ->
kill -9 $(sudo lsof -t -i:3000)
Related
I have a TypeScript Express application inside an Ubuntu 20.x server and I just did a code update and when I attempt to run a node build/app.js, I get the following error:
> > node build/app.js
>
> node:events:498
> throw er; // Unhandled 'error' event
> ^
>
> Error: listen EADDRINUSE: address already in use :::8080
> at Server.setupListenHandle [as _listen2] (node:net:1330:16)
> at listenInCluster (node:net:1378:12)
> at Server.listen (node:net:1465:7)
> at Function.listen (/home/ubuntu/wmui/service-integration/node_modules/express/lib/application.js:618:24)
> at Object.<anonymous> (/home/ubuntu/wmui/service-integration/build/app.js:70: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: 8080 }
I run sudo lsof -i :8080 and then get the pid and then run kill -9 <PID>, but that does absolutely nothing.
What next?
I have also tried this command: kill $(lsof -t -i:8080) and this command: kill -9 $(lsof -t -i:8080)
When I run another lsof -i:8080 I no longer see it listening to 8080, it just says:
node\x20/ 82822 user 21u IPv6 123456 0t0 TCP *:http-alt(LISTEN)
I have :
One docker container containing a server with a node-js app.
One docker container containing a postgres database.
There is a connection between these two.
Once I reboot the Postgres server the app crashes and wont restart until I manually restart it.
I'm using pm2 to run the nodejs app and thats what I get when pm2 logs
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
/root/.pm2/pm2.log last 15 lines:
PM2 | 2021-09-22T12:58:58: PM2 log: pid=1947 msg=process killed
PM2 | 2021-09-22T12:58:58: PM2 log: App [myApp:0] starting in -fork mode-
PM2 | 2021-09-22T12:58:58: PM2 log: App [myApp:0] online
PM2 | 2021-09-22T13:00:24: PM2 log: Change detected on path package.json.989998446 for app myApp - restarting
PM2 | 2021-09-22T13:00:24: PM2 log: Stopping app:myApp id:0
PM2 | 2021-09-22T13:00:24: PM2 log: App [myApp:0] exited with code [0] via signal [SIGINT]
PM2 | 2021-09-22T13:00:24: PM2 log: pid=1955 msg=process killed
PM2 | 2021-09-22T13:00:24: PM2 log: App [myApp:0] starting in -fork mode-
PM2 | 2021-09-22T13:00:24: PM2 log: App [myApp:0] online
PM2 | 2021-09-22T13:00:25: PM2 log: Change detected on path package-lock.json.95280979 for app myApp - restarting
PM2 | 2021-09-22T13:00:25: PM2 log: Stopping app:myApp id:0
PM2 | 2021-09-22T13:00:25: PM2 log: App [myApp:0] exited with code [0] via signal [SIGINT]
PM2 | 2021-09-22T13:00:25: PM2 log: pid=2005 msg=process killed
PM2 | 2021-09-22T13:00:25: PM2 log: App [myApp:0] starting in -fork mode-
PM2 | 2021-09-22T13:00:25: PM2 log: App [myApp:0] online
/root/.pm2/logs/myApp-error.log last 15 lines:
0|myApp | at Function.Module._load (internal/modules/cjs/loader.js:708:14)
0|myApp | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
0|myApp | at internal/main/run_main_module.js:17:47
0|myApp | /home/ubuntu/Project/bootcamp-app/node_modules/postgres/lib/backend.js:177
0|myApp | if (backend.query.result.command) {
0|myApp | ^
0|myApp |
0|myApp | TypeError: Cannot read property 'result' of undefined
0|myApp | at Object.RowDescription (/home/ubuntu/Project/bootcamp-app/node_modules/postgres/lib/backend.js:177:23)
0|myApp | at Socket.data (/home/ubuntu/Project/bootcamp-app/node_modules/postgres/lib/connection.js:161:25)
0|myApp | at Socket.emit (events.js:314:20)
0|myApp | at addChunk (_stream_readable.js:297:12)
0|myApp | at readableAddChunk (_stream_readable.js:272:9)
0|myApp | at Socket.Readable.push (_stream_readable.js:213:10)
0|myApp | at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
/root/.pm2/logs/myApp-out.log last 15 lines:
0|myApp | errno: 'ECONNREFUSED',
0|myApp | code: 'ECONNREFUSED',
0|myApp | syscall: 'connect',
0|myApp | address: '**.**.***.***',//edited that for safety
0|myApp | port: 5432
0|myApp | }
0|myApp | Error: connect ECONNREFUSED **.**.***.***:5432
0|myApp | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
0|myApp | errno: 'ECONNREFUSED',
0|myApp | code: 'ECONNREFUSED',
0|myApp | syscall: 'connect',
0|myApp | address: '**.**.***.***',
0|myApp | port: 5432
0|myApp | }
0|myApp | [nodemon] app crashed - waiting for file changes before starting...
any suggestions?
Error: Failed to load gRPC binary module because it was not installed for the current system
api_1 | Expected directory: node-v72-linux-x64-musl
api_1 | Found: [node-v64-linux-x64-glibc, node-v72-linux-x64-glibc, node-v83-linux-x64-glibc]
api_1 | This problem can often be fixed by running "npm rebuild" on the current system
api_1 | Original error: Cannot find module '/usr/src/app/node_modules/grpc/src/node/extension_binary/node-v72-linux-x64-musl/grpc_node.node'
api_1 | Require stack:
api_1 | - /usr/src/app/node_modules/grpc/src/grpc_extension.js
api_1 | - /usr/src/app/node_modules/grpc/src/client_interceptors.js
api_1 | - /usr/src/app/node_modules/grpc/src/client.js
api_1 | - /usr/src/app/node_modules/grpc/index.js
api_1 | - /usr/src/app/middleware/license.js
api_1 | - /usr/src/app/app.js
api_1 | at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/grpc_extension.js:53:17)
api_1 | at Module._compile (internal/modules/cjs/loader.js:1015:30)
api_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
api_1 | at Module.load (internal/modules/cjs/loader.js:879:32)
api_1 | at Function.Module._load (internal/modules/cjs/loader.js:724:14)
api_1 | at Module.require (internal/modules/cjs/loader.js:903:19)
api_1 | at require (internal/modules/cjs/helpers.js:74:18)
api_1 | at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/client_interceptors.js:144:12)
api_1 | at Module._compile (internal/modules/cjs/loader.js:1015:30)
api_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
api_1 | at Module.load (internal/modules/cjs/loader.js:879:32)
api_1 | at Function.Module._load (internal/modules/cjs/loader.js:724:14)
api_1 | at Module.require (internal/modules/cjs/loader.js:903:19)
api_1 | at require (internal/modules/cjs/helpers.js:74:18)
api_1 | at Object.<anonymous> (/usr/src/app/node_modules/grpc/src/client.js:35:27)
api_1 | at Module._compile (internal/modules/cjs/loader.js:1015:30) {
api_1 | code: 'MODULE_NOT_FOUND'
api_1 | }
i am trying to run from inside a docker container i tried changing the node version but still cant solve it i tried node v 12 and 14
had the same problem, this fixed it
npm install --target=12.0.0 --target_platform=linux --target_arch=x64 --target_libc=musl
I'm having Node.js that I'm trying to dockerize. There is a piece of code that provides Google Application Credentials stored in serviceAccount.json file that looks like this:
const googleApplicationCredentials = config.GOOGLE_APPLICATION_CREDENTIALS;
const serviceAccount = require(googleApplicationCredentials);
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
databaseURL: "https://databasename.firebaseio.com"
});
Path to this credential file is pulled from docker-compose which looks like this:
api:
build:
dockerfile: Dockerfile.dev
context: ./server
volumes:
- /app/node_modules
- ./server:/app
environment:
- GOOGLE_APPLICATION_CREDENTIALS="/app/serviceAccount.json"
Docker file is this:
FROM node:14.14.0-alpine
WORKDIR "/app"
COPY ./package.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "start"]
When I ssh to docker container, I can see serviceAccount.json under working directory /app.
However, when I start docker-componse I'm getting the following error:
Cred:"/app/serviceAccount.json"
api_1 | internal/modules/cjs/loader.js:883
api_1 | throw err;
api_1 | ^
api_1 |
api_1 | Error: Cannot find module '"/app/serviceAccount.json"'
api_1 | Require stack:
api_1 | - /app/src/firebaseInit.js
api_1 | - /app/src/services/notification.service.js
api_1 | - /app/src/controllers/messages.controller.js
api_1 | - /app/src/routes/consultingchannel.routes.js
api_1 | - /app/src/express.js
api_1 | - /app/src/server.js
api_1 | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
api_1 | at Function.Module._load (internal/modules/cjs/loader.js:725:27)
api_1 | at Module.require (internal/modules/cjs/loader.js:952:19)
api_1 | at require (internal/modules/cjs/helpers.js:88:18)
api_1 | at Object.<anonymous> (/app/src/firebaseInit.js:8:24)
api_1 | at Module._compile (internal/modules/cjs/loader.js:1063:30)
api_1 | at Module._compile (/app/node_modules/pirates/lib/index.js:99:24)
api_1 | at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
api_1 | at Object.newLoader [as .js] (/app/node_modules/pirates/lib/index.js:104:7)
api_1 | at Module.load (internal/modules/cjs/loader.js:928:32)
api_1 | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
api_1 | at Module.require (internal/modules/cjs/loader.js:952:19)
api_1 | at require (internal/modules/cjs/helpers.js:88:18)
api_1 | at Object.<anonymous> (/app/src/services/notification.service.js:4:1)
api_1 | at Module._compile (internal/modules/cjs/loader.js:1063:30)
api_1 | at Module._compile (/app/node_modules/pirates/lib/index.js:99:24)
api_1 | at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
api_1 | at Object.newLoader [as .js] (/app/node_modules/pirates/lib/index.js:104:7)
api_1 | at Module.load (internal/modules/cjs/loader.js:928:32)
api_1 | at Function.Module._load (internal/modules/cjs/loader.js:769:14)
api_1 | at Module.require (internal/modules/cjs/loader.js:952:19)
api_1 | at require (internal/modules/cjs/helpers.js:88:18) {
api_1 | code: 'MODULE_NOT_FOUND',
api_1 | requireStack: [
api_1 | '/app/src/firebaseInit.js',
api_1 | '/app/src/services/notification.service.js',
api_1 | '/app/src/controllers/messages.controller.js',
api_1 | '/app/src/routes/consultingchannel.routes.js',
api_1 | '/app/src/express.js',
api_1 | '/app/src/server.js'
api_1 | ]
api_1 | }
api_1 | [nodemon] app crashed - waiting for file changes before starting...
client_1 | Compiled with warnings.
UPDATE:
Finally realized very obvious problem. I should not have quotes around environment variable. Correct entry should be:
environment:
- GOOGLE_APPLICATION_CREDENTIALS=/app/serviceAccount.json
See your volumes definition in docker-compose, you mount your /server directory to /app. I guess that explains why it works when you ssh into the container, while it doesn't when you docker-compose up - in the latter case no volume is mounted.
volumes:
- /app/node_modules
# The culprit?
- ./server:/app
not able to create docker image for node.js app
getting ReferenceError: load_fonts is not defined:
WARNING: Some services (app) use the 'deploy' key, which will be ignored. Compose does not support 'deploy' configuration - use `docker stack deploy` to deploy to a swarm.
Starting appdc_app_1 ... done
Attaching to appdc_app_1
app_1 |
app_1 | > express-docker-app#1.0.0 start /usr/src/app
app_1 | > node app.js
app_1 |
app_1 | /usr/src/app/app.js:806
app_1 | load_fonts({
app_1 | ^
app_1 |
app_1 | ReferenceError: load_fonts is not defined
app_1 | at Object.<anonymous> (/usr/src/app/app.js:806:1)
app_1 | at Module._compile (internal/modules/cjs/loader.js:936:30)
app_1 | at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)
app_1 | at Module.load (internal/modules/cjs/loader.js:790:32)
app_1 | at Function.Module._load (internal/modules/cjs/loader.js:703:12)
app_1 | at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
app_1 | at internal/main/run_main_module.js:17:11
app_1 | npm ERR! code ELIFECYCLE