not able to dockerize node.js application - node.js

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

Related

Node Js app crashes after rebooting postgres server

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 when trying to run from a docker container

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

Node.js in docker-compose container can't access resource using absolute path

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

pm2 logs error port:3000 please fix this error

/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)

Permission Issue with starting react

I have an issue with web app running on react, In fact, react fail to start on browser and sone error in terminal.
Can you help please.
/app/node_modules/webpack-cli/bin/cli.js:281
node_1 | throw err;
node_1 | ^
node_1 |
node_1 | Error: EACCES: permission denied, unlink '/app/public/build/fonts/palmhr.8008cff1.ttf'
node_1 | at Object.unlinkSync (fs.js:956:3)
node_1 | at rimrafSync (/app/node_modules/rimraf/rimraf.js:314:17)
node_1 | at /app/node_modules/rimraf/rimraf.js:350:5
node_1 | at Array.forEach (<anonymous>)
node_1 | at rmkidsSync (/app/node_modules/rimraf/rimraf.js:349:26)
node_1 | at rmdirSync (/app/node_modules/rimraf/rimraf.js:342:7)

Resources