ENOENT: no such file or directory when using MongoDB SSL Certificate
I have a failed deploy and I'm getting the below error. I think it's because of the path of the ssl mongodb certificate. Any ideas how I should do it?
I'm using DigitalOcean for my mongodb and disabling ssl cannot be done, it's mandatory.
MONGO_URL: 'mongodb+srv://user:key@host/admin?authSource=admin&replicaSet=mongodb-fra1-70792&tls=true&tlsCAFile=C:/Meteor/project/.deploy/ca/ca-certificate.crt'
`=> Requesting Logs => Downloading Logs i-097c392f265db35a3 web.stdout.log
Dec 31 19:01:40 ip-172-31-9-135 web: npm ERR! code ELIFECYCLE
Dec 31 19:01:40 ip-172-31-9-135 web: npm ERR! errno 1
Dec 31 19:01:40 ip-172-31-9-135 web: npm ERR! [email protected] start: bash ./start.sh
Dec 31 19:01:40 ip-172-31-9-135 web: npm ERR! Exit status 1
Dec 31 19:01:40 ip-172-31-9-135 web: npm ERR!
Dec 31 19:01:40 ip-172-31-9-135 web: npm ERR! Failed at the [email protected] start script.
Dec 31 19:01:40 ip-172-31-9-135 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Dec 31 19:01:40 ip-172-31-9-135 web: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
Dec 31 19:01:40 ip-172-31-9-135 web: npm ERR! A complete log of this run can be found in:
Dec 31 19:01:40 ip-172-31-9-135 web: npm ERR! /home/webapp/.npm/_logs/2021-12-31T19_01_40_641Z-debug.log
Dec 31 19:01:41 ip-172-31-9-135 web: > [email protected] start /var/app/current
Dec 31 19:01:41 ip-172-31-9-135 web: > bash ./start.sh
Dec 31 19:01:41 ip-172-31-9-135 web: nvm is not compatible with the npm config "prefix" option: currently set to "/opt/elasticbeanstalk/node-install/node-v14.18.2-linux-x64"
Dec 31 19:01:41 ip-172-31-9-135 web: Run npm config delete prefix or nvm use --delete-prefix v12.22.1 --silent to unset it.
Dec 31 19:01:41 ip-172-31-9-135 web: Node version
Dec 31 19:01:41 ip-172-31-9-135 web: v12.22.1
Dec 31 19:01:41 ip-172-31-9-135 web: Npm version
Dec 31 19:01:42 ip-172-31-9-135 web: 6.14.12
Dec 31 19:01:42 ip-172-31-9-135 web: => Starting health check server
Dec 31 19:01:42 ip-172-31-9-135 web: => Starting App
Dec 31 19:01:43 ip-172-31-9-135 web: (node:21596) [DEP0131] DeprecationWarning: The legacy HTTP parser is deprecated.
Dec 31 19:01:43 ip-172-31-9-135 web: internal/fs/utils.js:269
Dec 31 19:01:43 ip-172-31-9-135 web: throw err;
Dec 31 19:01:43 ip-172-31-9-135 web: ^
Dec 31 19:01:43 ip-172-31-9-135 web: Error: ENOENT: no such file or directory, open 'C:/Meteor/project/.deploy/ca/ca-certificate.crt'
Dec 31 19:01:43 ip-172-31-9-135 web: at Object.openSync (fs.js:462:3)
Dec 31 19:01:43 ip-172-31-9-135 web: at Object.readFileSync (fs.js:364:35)
Dec 31 19:01:43 ip-172-31-9-135 web: at /var/app/current/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/operations/connect.js:255:32
Dec 31 19:01:43 ip-172-31-9-135 web: at Array.forEach (bash ./start.sh
Dec 31 19:01:43 ip-172-31-9-135 web: npm ERR! Exit status 1
Dec 31 19:01:43 ip-172-31-9-135 web: npm ERR!
Dec 31 19:01:43 ip-172-31-9-135 web: npm ERR! Failed at the [email protected] start script.
Dec 31 19:01:43 ip-172-31-9-135 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Dec 31 19:01:43 ip-172-31-9-135 web: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
Dec 31 19:01:43 ip-172-31-9-135 web: npm ERR! A complete log of this run can be found in:
Dec 31 19:01:43 ip-172-31-9-135 web: npm ERR! /home/webapp/.npm/_logs/2021-12-31T19_01_43_863Z-debug.log
Dec 31 19:01:44 ip-172-31-9-135 web: > [email protected] start /var/app/current
Dec 31 19:01:44 ip-172-31-9-135 web: > bash ./start.sh
Dec 31 19:01:44 ip-172-31-9-135 web: nvm is not compatible with the npm config "prefix" option: currently set to "/opt/elasticbeanstalk/node-install/node-v14.18.2-linux-x64"
Dec 31 19:01:44 ip-172-31-9-135 web: Run npm config delete prefix or nvm use --delete-prefix v12.22.1 --silent to unset it.
Dec 31 19:01:45 ip-172-31-9-135 web: Node version
Dec 31 19:01:45 ip-172-31-9-135 web: v12.22.1
Dec 31 19:01:45 ip-172-31-9-135 web: Npm version
Dec 31 19:01:45 ip-172-31-9-135 web: 6.14.12
Dec 31 19:01:45 ip-172-31-9-135 web: => Starting health check server
Dec 31 19:01:45 ip-172-31-9-135 web: => Starting App
Dec 31 19:01:47 ip-172-31-9-135 web: (node:21974) [DEP0131] DeprecationWarning: The legacy HTTP parser is deprecated.
Dec 31 19:01:47 ip-172-31-9-135 web: internal/fs/utils.js:269
Dec 31 19:01:47 ip-172-31-9-135 web: throw err;
Dec 31 19:01:47 ip-172-31-9-135 web: ^
Dec 31 19:01:47 ip-172-31-9-135 web: Error: ENOENT: no such file or directory, open 'C:/Meteor/project/.deploy/ca/ca-certificate.crt'
Dec 31 19:01:47 ip-172-31-9-135 web: at Object.openSync (fs.js:462:3)
Dec 31 19:01:47 ip-172-31-9-135 web: at Object.readFileSync (fs.js:364:35)
Dec 31 19:01:47 ip-172-31-9-135 web: at /var/app/current/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/operations/connect.js:255:32
Dec 31 19:01:47 ip-172-31-9-135 web: at Array.forEach (bash ./start.sh
Dec 31 19:01:47 ip-172-31-9-135 web: npm ERR! Exit status 1
Dec 31 19:01:47 ip-172-31-9-135 web: npm ERR!
Dec 31 19:01:47 ip-172-31-9-135 web: npm ERR! Failed at the [email protected] start script.
Dec 31 19:01:47 ip-172-31-9-135 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Dec 31 19:01:47 ip-172-31-9-135 web: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
Dec 31 19:01:47 ip-172-31-9-135 web: npm ERR! A complete log of this run can be found in:
Dec 31 19:01:47 ip-172-31-9-135 web: npm ERR! /home/webapp/.npm/_logs/2021-12-31T19_01_47_126Z-debug.log
Dec 31 19:01:47 ip-172-31-9-135 web: > [email protected] start /var/app/current
Dec 31 19:01:47 ip-172-31-9-135 web: > bash ./start.sh
Dec 31 19:01:47 ip-172-31-9-135 web: nvm is not compatible with the npm config "prefix" option: currently set to "/opt/elasticbeanstalk/node-install/node-v14.18.2-linux-x64"
Dec 31 19:01:47 ip-172-31-9-135 web: Run npm config delete prefix or nvm use --delete-prefix v12.22.1 --silent to unset it.
Dec 31 19:01:48 ip-172-31-9-135 web: Node version
Dec 31 19:01:48 ip-172-31-9-135 web: v12.22.1
Dec 31 19:01:48 ip-172-31-9-135 web: Npm version
Dec 31 19:01:48 ip-172-31-9-135 web: 6.14.12
Dec 31 19:01:48 ip-172-31-9-135 web: => Starting health check server
Dec 31 19:01:48 ip-172-31-9-135 web: => Starting App`
@zodern any help on this please 🙏
@MJO9, first of all, it is best if you keep MongoDB and app servers with the same provider, for the best availability and latency. How about you try to put your certificate in your Meteor project in a location like Your_app/server/private/ssl_certificate and add the file to gitignore so you don't save it in your repo. Then reference it as /server/private/certificate.
@paulincai Thanks for the tip
I tried to move the ssl certificate as you suggested but I still get the same error. Any other ideas?
https://mongodb.github.io/node-mongodb-native/2.2/tutorials/connect/ssl/
@paulincai Thanks for the link.
The reason I always get "no such file" no matter where I place the .crt is that the script making the connection is running on the server not on my PC. Have a look at the below error:
/built_app/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/operations/connect.js:255:32
I looked into MUP docs to see if there's a way to pass .crt of the mongo server to the app server but it looks like it's not supported.
I have no idea on how to get the .crt file into that location on the server! nay suggestion?
Error: ENOENT: no such file or directory, open '/ca/ca-certificate.crt' at Object.openSync (fs.js:462:3) at Object.readFileSync (fs.js:364:35) at /built_app/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/operations/connect.js:255:32
@MJO9 I never referenced a certificate but I use service configuration files for Firebase and never had an issue. What you need to consider is that your file needs to go together within your Meteor bundle because the EC2 machines are being rebuilt every time you deploy and local files are volatile. In Meteor, what is directly in the app_name directory, like: imports, lib, node_modules, server, packages, package.json etc ... are considered in the "root", from there all absolute paths are being created: /app_name/imports/..., /app_name/lib.... etc. Relative paths reference a file/folder in relation with another file/folder such as '../../imports/file.js' which is similar to 'app_name/imports/file.js'
Unless somebody gives you a better answer, I would place the file in different locations and try to reference it from there. Use console.log() to output your paths to the EBS console (pull the logs from EBS and check the file web.stdout.log, this is your NODE console).
@MJO9 ok, I think it would be best to start by using relative paths. Ex: app
-
server _ private/certificate.crt
-
imports _ api/collections/your_collection/index.js
in index.js
const cr = require('../../../server/private/certificate.crt')
And how to include it in the MongoDB connection string?
@paulincai And how to include it in the MongoDB connection string?