nodeJS ReferenceError : navigator is not defined. - node.js

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.

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.

Related

I am getting an error while creating a Project of Phonegap through Node.js in my mac

I Installed Node Js and Git on my Mac. Through Node JS i am downloading the phonegap and than creating its project on my desktop. Heres what i am getting in return, could somebody tell me what am doing wrong?
Aleems-MacBook-Pro:desktop aleemahmad$ phonegap create Cartoonsmart
/usr/local/lib/node_modules/phonegap/lib/phonegap/util/connect-proxy.js:21
fs.readFile(settings, (err, data) => {
^^
SyntaxError: Unexpected token =>
at exports.runInThisContext (vm.js:73:16)
at Module._compile (module.js:443:25)
at Object.Module._extensions..js (module.js:478:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (/usr/local/lib/node_modules/phonegap/lib/phonegap/serve.js:9:23)
at Module._compile (module.js:460:26)
at Object.Module._extensions..js (module.js:478:10)
Aleems-MacBook-Pro:desktop aleemahmad$
For creating new project in Phonegap,
the command is
phonegap create [foldername] [packagename] [projectname]
For example ::
phonegap create Demo com.demo Demo.
In this first "Demo" is folder name,
com.demo is package name,
Demo is project name/application name.
Try this, It will work for you.
Thanks

unable to install meanjs on linux mint

it has been one week now that i was trying to install meanjs stack and had no success.
Everytime I follow some tutorial and get errors. Now I end up with many issues, too much nodejs version, i dont know which one should be with what and why do karma not working ...etc
is there anyway to remove everything and install meanjs correctly and get it running successfully
+ WARNING: It is strongly recommended that you change sessionSecret config while running in production!
Please add `sessionSecret: process.env.SESSION_SECRET || 'super amazing secret'` to
`config/env/production.js` or `config/env/local.js`
/opt/mean/node_modules/connect-mongo/src/index.js:3
const Promise = require('bluebird');
^^^^^
error: uncaughtException: Use of const in strict mode. date=Mon Jul 18 2016 19:15:59 GMT+0400 (GST), pid=29602, uid=1000, gid=1000, cwd=/opt/mean, execPath=/usr/local/bin/node, version=v0.10.33, argv=[node, /opt/mean/server], rss=47960064, heapTotal=35267072, heapUsed=18951416, loadavg=[0.5966796875, 0.453125, 0.66748046875], uptime=4058.491096953
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
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. (/opt/mean/node_modules/connect-mongo/index.js:1:80)
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. (/opt/mean/config/lib/express.js:12:16)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
below is my system config
Linux Mint 17.2 64-bit
NodeJS v0.10.33
npm 1.4.28
bower 1.7.9
mongodb v3.0.12
Can anyone please help me, I want to get started.
I haven't dug into it, but I'm guessing the version of node you have doesn't support the 'const' keyword. 0.10.x is a (fairly) old version of node; have you considered upgrading to one of the versions that has ES 6 native support?

Type Error: require(...) is not a function in SendGrid NodeJS

I am trying to send emails using the following doc on sendrid:
https://sendgrid.com/docs/Integrate/Code_Examples/v2_Mail/nodejs.html
My app.js looks like this:
var sendgrid = require('sendgrid')('SENDGRID_APIKEY');
When runnig npm start I get the following error:
var sendgrid = require('sendgrid')(conf);
^
TypeError: require(...) is not a function
at Object.<anonymous> (C:\Users\Grandullon\Desktop\angular\app.js:8:36)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (C:\Users\Grandullon\Desktop\angular\bin\www:7:11)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
Any ideas what I am doing wrong? conf is a variable where I store my API key.
I am using a clean express installation.
THANKS
My package.json can be looked here as requested:
http://pastebin.com/pGKWFReX
The latest documentation shows a different structure for initialization.
You should try doing
var sg = require('sendgrid').SendGrid(conf);

AssertionError: path must be a string is thrown when requiring own module

I wanted to create a very minified version of hapi-ninja and came across following problem:
var settings = require('./app/server/config/settings');
var routes = require('./app/server/config/rout');
The first line works as it should an returns my modules. But the second line throws following Exception
AssertionError: path must be a string
at Module.require (module.js:362:3)
at require (module.js:380:17)
at Object.<anonymous> (/home/hknlof/development/mygit/todos/app/server/config/rout.js:8:21)
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> (/home/hknlof/development/mygit/todos/tryout.js:1:75)
I am running on Node v0.10.25 and hapi-ninja is working fine. When I don't require the rout module it does work. My rout and settings modules look very much the same as in hapi-ninja. I isolated the two require statements in one file. Tried both on their own, still the same result. Can't get my head around this. Tried debugging but the value of the node internal path does never change to the above string. Encoding ist always utf-8.
Thank you vkuchartkin and Tracker1.
So my mistake was that I forgot to require a certain directory in my rout.js
var getController = require(module, '../controller');
was my code. Should have been:
var requireDir = require('require-directory');
var get Controller = requireDir(module, '../controller');
Now I feel a bit stupid

Cannot find module in Nodejs

module.js:340
throw err;
^
Error: Cannot find module './models/todo'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\Basel\Desktop\Todo List\routes\api.js:1:74)
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)
C:\Users\Basel\Desktop\Todo List>
Why this application won't start up? I've already tried a global npm install.
In ./models/todo, the period indicates that node will look in the same folder that api.js is in, which would look for \Todo List\routes\models\todo.js. This does not start from the root of the application. To require this, you'll need to us two periods to jump up a level, and specify the app path as well:
var todo = require('../app/models/todo');
maybe you did not set the system value : NODE_PATH; it should point to your global module location;
in Linux: export NODE_PATH=/usr/local/lib/node_modules/ works good for me;
in my case, the file name i had given in my require statement was wrong. I had my models file named posts.js and i was using require('./models/post'). It worked after i changed it to require ('.models/posts')

Resources