Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodeJS ReferenceError : navigator is not defined.

Hello I'm trying to make some Javascript files working on nodeJS everything is well set however here is the error I get :

C:\>node myServer.js

C:\myFunctionsCallTest.js:750
if( (j_lm && (navigator.appName == "Microsoft Internet Explorer")) || navigato
              ^
ReferenceError: navigator is not defined
    at Object.<anonymous> (C:\myFunctionsCallTest.js:750:15)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\myServer.js:1:79)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)

C:\>

The files I'm using are :

myServer.js

var my_module = require("./myFunctionsCallTest.js");
console.log("RSA encrypted message :"+ my_module.Encrypt("myKey","myMessage"));

myFunctionsCallTest.js //This file contains some call of prototypes like : 
.....................................
RSAKey.prototype.setPublic = RSASetPublic;
RSAKey.prototype._short_encrypt = RSAEncrypt;
RSAKey.prototype.encrypt = RSAEncryptLong;
RSAKey.prototype.encrypt_b64 = RSAEncryptB64;
..............................................

Any idea from where this issue could come? Thanks.

like image 831
OussamaLord Avatar asked Jul 09 '26 17:07

OussamaLord


1 Answers

It looks like you're using Tom Wu's BitInteger and RSA JavaScript library. This library was designed for use in the browser and doesn't work quite right in Node.js.

Luckily, someone has already gone through the work of packaging this library in a Node.js compatible format; it's on GitHub at https://github.com/eschnou/node-bignumber and available via npm as the package "bignumber", and comes with a nice example.

like image 64
Michelle Tilley Avatar answered Jul 11 '26 11:07

Michelle Tilley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!