Strange Error in using consolelog in nodejs - node.js

Using node.js 0.10.24.
I got an error telling me that "Object has no method log" in 6th line in following code.
But when 3rd line enabled, no problem. Anyone know why?
var EE=require("events").EventEmitter;
var on=EE.prototype.on;
//var c=console;
EE.prototype.on=function(event,handler){
console.log("added "+event);
on.call(this,event,handler);
};
var server=require('http').createServer();

Related

graphClient.Directory.AdministrativeUnits

I am trying to get AdministrativeUnits using the Microsoft.Graph.Api, but when I write the following lines I get error on Directory.AdministrativeUnits
var administrativeUnits = await graphClient.Directory.AdministrativeUnits.Request().GetAsync();
The graphClient.Directory doesnt have AdministrativeUnits what am I missing?
from here:
https://learn.microsoft.com/en-us/graph/api/administrativeunit-list?view=graph-rest-1.0&tabs=csharp

Module `fs` does not exist in the Haste module map

I'm new to Node.js and react-native. I followed the sample on send_telemetry.js exactly but when I run my react-native app I get an error: "The development server returned response error code 500.
the error message is:
bundling failed: Error: Unable to resolve module fs from ProjectPath\node_modules\azure-iot-device\lib\module_client.js: Module fs does not exist in the Haste module map";
Im running:
Node.js v10.15.3
NPM 6.4.1
react-native#0.59.2
First error was the same with Unable to resolve module events,
I can install events,
but the fs module is: "This package name is not currently in use, but was formerly occupied by another package. To avoid malicious use, npm is hanging on to the package name, but loosely, and we'll probably give it to you if you want it."
var Protocol = require('azure-iot-device-http').Http;
var DeviceClient = require('azure-iot-device').Client;
var Message = require('azure-iot-device').Message;
var connectionString = 'my connection string';
var client = DeviceClient.fromConnectionString(connectionString, Protocol);
function ConnectionTest(err) {
if (err) {
console.log('Could not connect: ' + err);
} else {
console.log('Client connected');
}
client.close(function () {
process.exit(0);
});
};
export async function Test() {
client.open(ConnectionTest);
};
Basically I need to know how to get the azure IOT hub client working in my react-native app (not using Expo).
Im pretty much stumped so any help would greatly be appreciated.
A dependency module is missing ... which is fs ...
this file-system npm module is incompatible with react-native ... cause it has it own different environment.
I had "import { symlink } from 'fs';" randomly pop up in one of my scripts. Once I deleted this line same issue you had went away. I would search your whole project for that line.

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' };

[TypeError: Object # has no method 'replace']

First off all. I'm not posting questions about the error reason. This suddenly appeared when running an node.js app where after executing the query this error was received. I just want to know how to find the line in the source code where this error appears. How to set node to display extended info in errors like this?
So the error would be displayed like:
[TypeError: Object # has no method 'replace'] Test.js 123:98
put line 123 in try and catch the error
try{
// line 123
} catch(e){
throw e;
}
so it will print the stack of the error

Node debug - undefined error

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.

Resources