bitpay / node-bitpay-client

A Node.js module and command line client for interacting with BitPay's Cryptographically Secure API
102 stars 95 forks source link

[Now specific] Cannot find module '/home/nowuser/.bitpay/config.json' #92

Open ksullivan91 opened 6 years ago

ksullivan91 commented 6 years ago

I followed the instructions while setting up the bitpay client and have no trouble running this in my local environment. However, when deploying to now.sh, I am receiving the error:

`

module.js:557 throw err; ^ Error: Cannot find module '/home/nowuser/.bitpay/config.json' at Function.Module._resolveFilename (module.js:555:15) at Function.Module._load (module.js:482:25) at Module.require (module.js:604:17) at require (internal/module.js:11:18) `

I have used the overloading configuration option specified in the documentation but it still tries to load the config.json file. I've created a folder named .bitpay in the root and it still isn't able to find the file.

Typically the deployment is served from '/home/nowuser/src' and bitpay is looking for the .bitpay file one level up at 'home/nowuser/.bitpay'

Any help would be appreciated!

ksullivan91 commented 6 years ago

I kind of solved this by cloning the repo, adding it to my project, and implementing this PR

gabmontes commented 5 years ago

Used https://github.com/ds300/patch-package to patch the repo as follows:

patch-package
--- a/node_modules/bitpay-rest/lib/rest-client.js
+++ b/node_modules/bitpay-rest/lib/rest-client.js
@@ -8,7 +8,12 @@ var util         = require('util');

 var isWin        = process.platform === 'win32';
 var HOME         = process.env[isWin ? 'USERPROFILE' : 'HOME'];
-var defaultConf  = require(HOME + '/.bitpay/config.json');
+
+try {
+  var defaultConf = require(HOME + '/.bitpay/config.json');
+} catch (e) {
+  var defaultConf = require('../config/test.json');
+}

 /*
 ** BitPay REST Client

Worked flawlessly.