Node debug - undefined error - node.js

I was exploring node debugger and I am stuck at the problem. I have a debugging.js file with following content
var http = require("http");
function process_request(req, res) {
var body = 'Thanks for calling!\n';
var content_length = body.lenggth ;
res.writeHead(200, {
'Content-Length': content_length,
'Content-Type': 'text/plain'
});
res.end(body);
}
var s = http.createServer(process_request);
s.listen(8080);
Note that there is an mistake on line 5. This is done intentionally to debug the problem. Now I tried running node using node debug debugging.js. While this didn't gave any error. Calling setBreakpoint(5) resulted in following error.
Warning: script 'undefined' was not loaded yet.
_debugger.js:1399
var escapedPath = script.replace(/([/\\.?*()^${}|[\]])/g, '\\$1');
^
TypeError: Cannot call method 'replace' of undefined
at Interface.setBreakpoint (_debugger.js:1399:31)
at repl:1:1
...
Environment : Debian Linux3.2.0, Node JS - V0.13.0-pre
Can someone tell me, what should be done to resolve this?
I found post, which seems to have similar problem, but it seems to be a year old post and I am not sure whether the fix is available in the node version, I am using.

Well it seems to be a problem with the node V0.13.0-pre, I am using on Linux. I tried same code on Windows with node v0.10.33 and its working well. All the debugging commands are working as expected.

Related

redis Error : ERR wrong number of arguments for 'set' command

i have an error with redis set command on local redis server(127.0.0.1:6379)
versions:
npm version : 2.15.0;
node version : 4.4.2;
nodejs verison : 0.10.25;
redis version : 2.7.1;
Error:
events.js:141 throw er; // Unhandled 'error' event
ReplyError: ERR wrong number of arguments for 'set' command at parseError
(/opt/xxx/xxx/node_modules/redis/node_modules/redis
parser/lib/parser.js:193:12) at parseType
(/opt/xxx/xxx/node_modules/redis/node_modules/redis-
parser/lib/parser.js:303:14)
all of my codes look like this:
redis.set("key","value")
on my local machine the code is running successfully , but on aws linux machine i got this error.
var matchedMaps = map.get(publicURIField);
if(matchedMaps) {
matchedMaps.forEach(function(matchedMap){
var patternToValidate = matchedMap.pattern;
var type = matchedMap.type;
var tagID = matchedMap.tagID;
var patternToCheck = "cs-uri-stem";
var patternToSave = "";
if(type==1){
patternToCheck = "c-referrer";
}
var regexToFind = new RegExp(patternToValidate.substring(1,patternToValidate.length-1));
var matchedPattern;
if (regexToFind.test(rawLogParsed[patternToCheck].toString())) {
if (matchedMap.regexType=="&"){
matchedMap.patterns.forEach(function(patternObject){
var key = patternObject.pattern.split("=")[0];
var value = rawLogParsed[patternToCheck].toString().split(key)[1];
if(rawLogParsed[patternToCheck].toString().split(key)[1].split("&")){
value = rawLogParsed[patternToCheck].toString().split(key)[1].split("&")[0];
}
patternToSave += key+value+"&";
});
}else{
matchedMap.patterns.forEach(function(patternObject){
if(patternObject.pattern.indexOf("*")>-1){
patternObject.pattern = patternObject.pattern.replace(/\*!/g, '.*');
}
patternToSave += rawLogParsed[patternToCheck].toString().match(patternObject.pattern)+"/";
});
}
patternToSave = patternToSave.substring(0,patternToSave.length-1);
var matchedField = publicURIField,matchedPattern = patternToSave
,key = tagID + "_"+userID+"_"+ matchedField + "_" + matchedPattern + "_" + type + "_" + fixedMinuteNumber;
if (tagUsageInfo[startKeyForRedis+key] == undefined) {
var tagObject = {
pattern:matchedPattern,
matchedField:matchedField,
userID:userID,
tagName:matchedMap.tagName,
monthNumber:parseInt(mMonthToCheck),
minuteNumber: parseInt(fixedMinuteNumber),
hourNumber: parseInt(yearMonthDayHourToCheck),
dayNumber: parseInt(yearMonthDayToCheck),
tagID: tagID,
matchedPattern: matchedPattern,
totalRequests: 1,
totalEgress: parseInt(bytes),
totalTransfered: parseInt(bytes),
totalRest: parseInt(totalWorld),
totalUS: parseInt(totalUS)
}
if(isIngress){
tagObject.totalIngres += parseInt(bytes);
}
dbclient1.set(startKeyForRedis+"tagUsage_"+key,JSON.stringify(tagObject));
tagUsageInfo[startKeyForRedis+"tagUsage_"+key] = startKeyForRedis+key;
}
else {
dbclient1.get(startKeyForRedis+"tagUsage_"+key, function(err, tagObject) {
var tagObjectJson = JSON.parse(tagObject);
tagObjectJson.totalRequests += 1;
tagObjectJson.totalEgress += parseInt(bytes);
tagObjectJson.totalTransfered += parseInt(bytes);
tagObjectJson.totalRest += parseInt(totalWorld);
tagObjectJson.totalUS += parseInt(totalUS);
tagObjectJson.totalRequests += 1;
if(isIngress){
tagObject.totalIngres += parseInt(bytes);
}
dbclient1.del(startKeyForRedis+"tagUsage_"+key);
dbclient1.set(startKeyForRedis+"tagUsage_"+key, JSON.stringify(tagObjectJson));
});
}
}
});
}
any help?
1)If your trying to run redis on windows set accepts only two arguments cause the redis version issue
2)try latest version of redis on linux it will work
Try installing this version of Redis on windows from the following link. You can find more information here https://github.com/ServiceStack/redis-windows
This link provides three options to install Redis on windows
Option 1) Install Redis on Ubuntu on Windows
Option 2) Running the latest version of Redis with Vagrant
Option 3) Running Microsoft's native port of Redis
I personally prefer option 3.
Hope this helped. Thanks.
all of my codes look like this: [...]
It's not important how all of your code looks like. It's important how the specific line that caused the problem looks like but unfortunately you didn't include it.
The errors that you provided include some files and line numbers but you seem to have removed the ones that are related to your code. If you read those messages carefully then you should be able to know what lines those errors are related to and focus on those lines.
If the errors show up on a server and not on your desktop then I would suspect that maybe you're trying to use some environment variables or files on the file system to populate some variables in your program, and those are not available on the server resulting in putting undefined there.
You will surely find the problem when you add console.log() statements to every place where you want to access Redis so that you first print it and then call to Redis. That way at least you will know what data is causing the problem. I suspect that you are having some undefined values or something like that.
Remember that JSON.stringify(undefined) returns undefined instead of a valid JSON string. Something like that may be causing problems. Adding debug messages will help to narrow it down.
Some extra advice: You can use prefix parameter of the redis module then you will not have to add startKeyForRedis+ all over the place. You can set a prefix once and have it prepended automatically. See the docs:
https://www.npmjs.com/package/redis
I was doing learning to use KUE a nodejs library for job scheduling that uses redis for saving data.
I got this error while running client.js(that puts jobs in queue) and worker.js(that process the schedule jobs).
I was running worker before running the client and that is why this happened.
I reversed the order and everything went fine!
To fix this error on windows Redis from v.3 required.
That's why I've took zipped release 3.0.504 from here and now all is working.
Quite simple.
I have faced similar type of error which was because of older version of Redis. This is compatibility issue which fixes a bug in Redis after Redis 2.6.12. Make sure you install recent version of Redis v3.X.

Script fails when using python-shell Node.js package

So I'm having a pretty odd issue. I have a python script whose function is to analyze an image and produce an output string. I decided to implement this script into the backend of my NodeJS server using the package 'python-shell.' The funny thing is, this script works perfectly when it's run on its own. It is able to analyze the image and produce the output string. However, when I attempt to have the 'python-shell' package run it, there is an error that is produced (related to the python code). I've tested and the python-shell runs the same version of python as is used at the terminal, so I'm not 100% sure why this issue is occurring. For reference, the below code is how I'm running the script:
var express = require('express');
var router = express.Router();
var pythonshell = require('python-shell');
pythonshell.defaultOptions = { scriptPath: '/path/to/myscript.py' };
var outputString = '';
var options = {args: ['-p', '/path/to/image.jpg']}
var pyshell = new pythonshell('myscript.py', options);
pyshell.on('message', function(message) {
// received a message sent from the Python script
console.log(message);
outputString = message;
});
pyshell.end(function(err) {
// This is where the error occurs
if (err) throw err;
console.log('Picture analysis complete');
console.log('outputString: ' + outputString);
});
Again, when the script is manually run (i.e. python myscript.py -p image.jpg), it runs perfectly fine. I can include the code in myscript.py, although I doubt that will help as it doesn't seem to be an error with the actual python code. The image is analyzed using several packages including OpenCV (and the produced error is, I believe, based off that). Any tips are greatly appreciated!
change the default path
pythonshell.defaultOptions = { scriptPath: '/path/to/myscript.py' };

In CasperJS scroll not working if we use it with PhantomJS

If we use casper without --engine=slimerjs the casper.scrollToBottom(); and casper.page.scrollPosition = {top: scrollHeight, left: 0}; is not working.
I mean if we use just $ casperjs file.js it not works. But with $ casperjs --engine=slimerjs file.js it works good enough.
Any suggestion?
maybe I should use something in command line? like --webdriver? I tried --ssl-protocol=any - IT ALSO DOESN'T HELPS. Or maybe I should include JS files like page.includeJs('https://www.my-site.com/thisjsfile.min.js')
P.S.: I'm not believe that it will be helpful but here is the code:
casper.then(function() {
this.waitForSelector('#myselector', function() {
this.open('http://www.my-site.com/messages');
this.echo('Open messages Inbox');
});
})
.then(function() {
this.repeat(timesForCasperRepeat, function() {
this.wait(5000, function() {
scrollHeight = this.evaluate(function() {
return document.body.scrollHeight;
});
this.echo('Scroll Height: ' + scrollHeight);
this.scrollToBottom();
this.echo('scrolling down', 'INFO_BAR');
});
});
});
even I change scrollToBottom() to:
this.page.scrollPosition = {
top: scrollHeight,
left: 0
};
I also included Anrtjom's handle errors events, there is a link
and there is the errors i have:
Error: ReferenceError: Can't find variable: ourvarname1
Error: ReferenceError: Can't find variable: jQuery
Error: ReferenceError: Can't find variable: ourvarname2
Error: ReferenceError: Can't find variable: ourvarname3
Error: TypeError: 'undefined' is not a function (evaluating 'RegExp.prototype.test.bind(/^(data|aria)-[a-z_][a-z\d_.\-]*$/)')
Console: Unsafe JavaScript attempt to access frame with URL http://www.my-site.com/messages from frame with URL http://ads.my-site.com/daisy?browser=windows_chrome&base=1&page=Mailbox&pageurl=%2fmessages&format=half_page&authid=1%2c0%2c1457605848%2c0xf290ca6243d86169%3beed7d0c7a540f963b5268452a4c95ac74793badc&cachebust=655998. Domains, protocols and ports must match.
found solution and it works for me, the problem was that casperjs use older version of phantomjs, so for mac users just go to folder where casperjs installed. For me it was: /usr/local/Cellar/casperjs/. And find folder with phantomjs: /usr/local/Cellar/casperjs/1.1-beta4/libexec/phantomjs and change it to new dowloaded from phantomjs website.
I found that casperjs used 1.9 version, but current phantomjs is 2.1.1, just changed folder to new one and no problems with it.

browserify watchify produces errors

I am using gulp, browserify and watchify. Here is my 'scripts' task:
gulp.task('scripts', function() {
var b = watchify(browserify(paths.app.root + '/client.js', watchify.args));
b.on('update', bundle);
return bundle();
function bundle() {
return b
.bundle()
.pipe(source('bundle.js'))
.pipe(gulp.dest(paths.build.root + '/scripts'));
}
});
client.js looks like:
require('request');
alert('1');
where request is node module (http client): https://github.com/request/request
When I run this task and execute the code - everything is fine. The problem starts when I change client.js. When I comment alert('1'), watchify start it's work and bundle() runs again. When I reload the page on the browser, I get the following javascript exception:
Uncaught TypeError: Cannot read property 'version' of undefined
with the following stack trace:
/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/browserify-sign/node_modules/elliptic/lib/elliptic.js.../package.jsonbundle.js:19825
/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/node_modules/elliptic/lib/elliptic.js.../package.jsonbundle.js:1
/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/ecdh.js.bn.js
/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/node_modules/create-ecdh/inject.js../ecdh
/Users/me/project/node_modules/browserify/node_modules/crypto-browserify/index.js.browserify-aes
/Users/me/project/node_modules/request/lib/helpers.js._process
/Users/me/project/node_modules/request/index.js../lib/cookies
./client.js.request
Any idea what is wrong with browserify / request?
It looks like it is an issue with elliptic, a dependency of browserify. See https://github.com/indutny/elliptic/issues/30
Hopefully this gets fixed up shortly.
Edit: It may actually be an issue with browserify. I would try reverting to 8.1.2 and seeing if that helps.

Node JS TypeError with `path.join` when serving webpage with Express

I've just installed Node JS (v0.10.0) on a netbook running Linux Peppermint Three. I have a file to run which has the following at the top:
var app = require('express').createServer(),
io = require('socket.io').listen(app);
app.listen(8080);
// routing
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
The problem is that when I visit localhost:8080 I get the following:
TypeError: Arguments to path.join must be strings
at path.js:360:15
at Array.filter (native)
at exports.join (path.js:358:36)
at exports.send (/home/guy/Dropbox/Node/socket_io echo test/node_modules/express/node_modules/connect/lib/middleware/static.js:129:20)
at ServerResponse.res.sendfile (/home/guy/Dropbox/Node/socket_io echo test/node_modules/express/lib/response.js:186:3)
at usernames (/home/guy/Dropbox/Node/socket_io echo test/med.js:11:7)
at callbacks (/home/guy/Dropbox/Node/socket_io echo test/node_modules/express/lib/router/index.js:272:11)
at param (/home/guy/Dropbox/Node/socket_io echo test/node_modules/express/lib/router/index.js:246:11)
at pass (/home/guy/Dropbox/Node/socket_io echo test/node_modules/express/lib/router/index.js:253:5)
at Router._dispatch (/home/guy/Dropbox/Node/socket_io echo test/node_modules/express/lib/router/index.js:280:5)
The exact same file works on my Windows XP laptop but I haven't updated Node there yet (still running v0.8.15). So I don't know if it's my installation of Node on Linux (to which I'm new) that's the problem or the disparity between versions. Obviously I don't want to update Node on Windows if it's going to result in the same problem.
I've checked that Express is where it should be and that seems okay. I've tried re-installing it via npm. I've looked up the error (by searching for the first line above) and found mentions here and here and here, where all seem to be saying it's resolved.
Any ideas what else (if anything) I can try to get my simple page server working?
I've encountered this as well, on node v0.10.2, while trying to upgrade from 0.6.14. The problem lies in the connect static middleware, and how it handles the paths and a possible regression in how path.join handles its args.
Here's the problematic code from connect
// setup
var maxAge = options.maxAge || 0
, ranges = req.headers.range
, head = 'HEAD' == req.method
, get = 'GET' == req.method
, root = options.root ? normalize(options.root) : null //<!-- should be ''
, redirect = false === options.redirect ? false : true
, getOnly = options.getOnly
, fn = options.callback
, hidden = options.hidden
, done;
Later, when the path is joined, you end up with a null, causing the error under v0.10.2
// join / normalize from optional root dir
path = normalize(join(root, path));
Under node 0.8.21, you get this
> require('path').join(null, 'file.txt');
'file.txt'
Under node 0.10.2, you get this instead
> require('path').join(null, 'file.txt');
TypeError: Arguments to path.join must be strings
at path.js:360:15
at Array.filter (native)
at Object.exports.join (path.js:358:36)
at repl:1:17
at REPLServer.self.eval (repl.js:110:21)
at repl.js:249:20
at REPLServer.self.eval (repl.js:122:7)
at Interface.<anonymous> (repl.js:239:12)
at Interface.EventEmitter.emit (events.js:95:17)
at Interface._onLine (readline.js:202:10)
TL;DR
You can monkey-patch your code in the meantime to work around the issue.
Absolute path
var filepath = '/some/absolute/path/to/file.ext';
res.sendfile(path.basename(filepath), {root: path.dirname(filepath)});
or
Relative path
res.sendfile('file.ext', {root: __dirname})
Setting {root: ''} will fail the truthy test in the static middleware.
The problem seemed to be an incompatibility with the new version of Node. I had to update Express to v3.1.0 and Socket.IO to v9.1.13. I also then had to update NodeJS on my Windows laptop to the latest version as installed on my Linux netbook, v0.10.1.
With everything across both computers up to date, the code (as quoted above) then needed changing to the following:
var app = require('express')(),
server = require('http').createServer(app),
io = require('socket.io').listen(server);
server.listen(8080);
// routing
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
Note the direct invocation of the Express module here, as opposed to the method call used previously. Also note that IO must listen to the server created around the Express invocation (i.e., not app as I had it before); this got around some problems with getting the Socket.IO script to launch on the client-side. At the time of writing I still don't fully understand how the script is accessed given where the page is being served from. I will try to come back and update this when I know more.
PS. I'm indebted to #robertklep who guided me through this, as you can probably see in the comments above. Thank you!
Quick fix
sed -i bak -e 's/\/\/.join/if(root\ ==\ null){root="";}\/\//g' node_modules/express/node_modules/connect/lib/middleware/static.js

Resources