Ask coding questions

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

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?

Comments
hotnewtop
realTronsi (929)

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 (2513)

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

realTronsi (929)

@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 (2513)

@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 (929)

@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 (2513)

@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 (18071)

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 (2513)

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

realTronsi (929)

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

RayhanADev (2513)

@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 (2513)

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

Coder100 (18071)

remember, it's either:

realTronsi (929)

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

Coder100 (18071)

global variables?
pffft what a noob @realTronsi

realTronsi (929)

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

illiterate?
pffft what a noob @Coder100

realTronsi (929)

@RayhanADev I have no mercy for people who put

console.log("Server running")

outside of the server callback

realTronsi (929)

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 (2513)

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

realTronsi (929)

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

RayhanADev (2513)

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

RayhanADev (2513)

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

Coder100 (18071)

well the thing is you can't xd @RayhanADev