Skip to content
This repository has been archived by the owner on Oct 10, 2018. It is now read-only.

Usage in npm module #33

Open
tnrich opened this issue Sep 11, 2015 · 3 comments
Open

Usage in npm module #33

tnrich opened this issue Sep 11, 2015 · 3 comments

Comments

@tnrich
Copy link

tnrich commented Sep 11, 2015

Hey there,

I had a question about how best to use api-check when using it in an npm module I'm developing. Currently I'm developing the module as a local module within a larger project, so it is just using the same api-check setup file as is used in the larger application. However, I'd like to soon split this local module out of my project to have it be its own stand-alone npm module.

I would still like to have api-check running for my stand-alone npm module, which I think means I'll need to duplicate the api-check setup file, and instead require it explicitly within the module this time.

I'm wondering if there will be a way to disable api-check for my now npm-required module when building my app in production. I guess the question boils down to: does api-check get disabled if its included in node_modules when building an app in production?

Hope this question makes sense. Thanks a bunch for the excellent package!
Thomas

@kentcdodds
Copy link
Owner

Glad you're using and benefitting from api-check! So api-check doesn't have any mechanism for disabling itself during production (maybe it should?) so you have to do so manually. In my app, when I build for production, what I do is:

var apiCheckFactory = require('api-check');
apiCheckFactory.globalConfig.disabled = process.env.NODE_ENV === 'production'; // <-- do this before anything else to get maximum perf benefits
var myInstanceOfApiCheck = apiCheckFactory();

So when you build your app, just set the NODE_ENV to production and you're set! I hope this helps.

@tnrich
Copy link
Author

tnrich commented Sep 11, 2015

Hmm thanks for your reply. I wonder what the best way would be to allow the user of the npm module to control this functionality. Maybe they'd want it to be disabled via the node_env variable, but maybe not... It seems like there must be a better way than hardcoding it into the module. Do you know of any other approaches that would allow the user to specify when/how it should be disabled?

Thanks again for all your work!

@kentcdodds
Copy link
Owner

So, you mean you're developing a library that uses api-check and you want
users to be able to disable your libraries instance?

Most of the time, they'd want to disable api-check globally. So you can
document how to do that before your library is loaded (they can do it how
they want). Or, if you want them to be able to disable your instance
specifically, you could expose an api for them yourself.

Let me know if I'm understanding you incorrectly.

On Fri, Sep 11, 2015, 12:03 PM Thomas Rich notifications@github.com wrote:

Hmm thanks for your reply. I wonder what the best way would be to allow
the user of the npm module to control this functionality. Maybe they'd want
it to be disabled via the node_env variable, but maybe not... It seems like
there must be a better way than hardcoding it into the module. Do you know
of any other approaches that would allow the user to specify when/how it
should be disabled?

Thanks again for all your work!


Reply to this email directly or view it on GitHub
#33 (comment)
.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants