Ask coding questions

← Back to all posts
Private Variables in NPM Package
h
RayhanADev

So I’m almost ready to release version 1.0.0 (working my way there :D) of my REPLAPI.it package but I need to know (if it’s even possible) how to make variables that cannot be tampered with by someone using a package. For example, is I have an array with secrets someone can change the array’s contents and if I have .env keys someone can just redefine them because it wouldn’t work. Any ideas?

Voters
G0RG3
RayhanADev
Comments
hotnewtop
realTronsi

Anyways yeah you don't use global variables in packages, and you also use module exports to export necessary functions. If you need a whitelist then no problem, the user can pass in their whitelist as a parameter.

RayhanADev

@realTronsi but THAT NOT THE POINT OF A WHITELIST. I get it, it’s impossible xd.

realTronsi

@RayhanADev wdym!!!! You dont use global variables inside packages. If you want to store some whitelist on your side then start up a server, and users can retrieve the whitelist from the server

RayhanADev

@realTronsi so, I create a server on a completely different thing and then retrive the veriable from the server. But can’t a user change that when its retrived?

realTronsi

@RayhanADev you're afraid a user can "change" the whitelist?? wdym, when you install a package, it essentially clones the files and adds it to your project, it doesn't link directly to the source and users aren't able to edit the source code silly goose.

If you're worried about private information then why tf are you storing private information in a package.

RayhanADev

@realTronsi okay
1. take mat1’s ReplTalk package. That’s what I want to avoid. He left the “whitelisted” bots out in the open so well. You know. cough, cough most spam bots on Repl.it.
2. It’s not that I want to store it on the package, I just don’t know how to go about this and am open to ideas!

Coder100

Nope, once someone HAS, they HAS. Just make the user pass them in themselves.

Anyways, why are you making a replapi.it package lol was mine not good enough xd

RayhanADev

@Coder100 ah darn, that sucks. Also because I can >:D, and it’ll have more features than any Repl API package ever xD

Coder100

like what xD @RayhanADev

realTronsi

@RayhanADev wow doesn't listen to me but listens to Coder >:C

RayhanADev

@Coder100

  • Repl support without Crosis aka recoding what Kognise wrote
  • More GraphQL queries than what mat1 gives

tbh I haven’t seen yours yet is it on NPM

RayhanADev

@realTronsi but you said you could but you couldn’t :(

Coder100

remember, it's either:

realTronsi

@RayhanADev ? I said you don't use global variables in npm packages.. that's what coder is saying too

Coder100

global variables?
pffft what a noob @realTronsi

RayhanADev

@Coder100 @realTronsi pls no argue xd

realTronsi

?? I'm saying you dont use global variables.

illiterate?
pffft what a noob @Coder100

Coder100
realTronsi

@RayhanADev I have no mercy for people who put

outside of the server callback

realTronsi

@Coder100 hi Mr.IDontUseCallbacks

realTronsi

how is that even an issue

cough cough module exports

also don't use global variables in your package, just define everything in a function as well

RayhanADev

@realTronsi wdym? What if want to check if a user is in a whilelist I created before I let them login?

realTronsi

@RayhanADev then have the user define the whitelist and use it...

RayhanADev

@realTronsi WHAT BUT THAT DEFEATS THE POINT OF A WHITELIST?!?!?!?!

RayhanADev

@realTronsi its a whitelist I created. Me, the owner of the package.

Coder100

well the thing is you can't xd @RayhanADev