Is `crypto` available in Glitch's version of node?


When I try to access the crypto object within my server.js, I get “ReferenceError: crypto is not defined”.

However, when I open the console, launch node and type > crypto, I see that it is available.

I do see the following note on the node docs for crypto:

It is possible for Node.js to be built without including support for the crypto module. In such cases, calling require(‘crypto’) will result in an error being thrown.

…but that doesn’t explain its availability in the console.

Any thoughts as to what’s going on?


Is there a Node version specified in your package.json? Does the version of Node on the console match the same version of Node in use by your app?


I checked the versions, and tried using the exact version I’m seeing in the console, as well as the latest available version (per nvm). Same result each time.


Hmm, I was able to reproduce the same behavior though calling var crypto = require('crypto') in my server.js resolved it for me. :ghost:


Sure enough! That worked for me as well.



According to the Node docs, all the built-in modules are automatically imported and assigned to global variables in the REPL.


Also according to Node.js docs, it is possible to build nodejs without crypto. however crypto is included by default. Though, the modules aren’t assign to global variables, what are you talking about? The only global variable I’m aware of is process and console.


Oops, I forgot to mention that that only happens in the REPL. Thanks for pointing that out.