I have installed Node.Js and Casper.js to perform webscraping and save the info into a DB. But I have a problem because when I try to execute the source, I get the following error in the terminal:
Error: Cannot find module './build/Release/mysql_bindings'
I have previously installed mysql-libmysqlclient with the mysql_bindings inside. I tested creating the route of the error, but it didn't work.
The code is:
var mysql = require('db-mysql');
new mysql.Database({
hostname: 'localhost',
user: 'rool',
password: 'xxxx',
database: 'xxxBD' }).connect(function(error) {
if (error) {
return console.log('CONNECTION error: ' + error);
}
this.query().
select('*').
from('tablaPruebas').
execute(function(error, rows, cols) {
if (error) {
console.log('ERROR: ' + error);
return;
}
console.log(rows.length + ' ROWS found');
});
});
Thanks in advance!
The problem is that your using the following in your code:
var mysql = require('db-mysql');
However your question shows that you have installed mysql-libmysqlclient. This means you should be using the following instead:
var mysql = require('mysql-libmysqlclient');
I presume you installed from https://github.com/Sannis/node-mysql-libmysqlclient
The code you're using looks more like db-mysql which can be found here
If you install via npm install db-mysql then you should be good. Have a look at the link I included for db-mysql as there appears to be a few dependencies (e.g. setting up MYSQL_CONFIG environment variable).
Related
I am trying to connect to a DB2 server but I am getting bellow given error.
I'm following the given documentation: npm db2 Doc
I have done npm i ibm_db2
Code:
const ibmdb = require('ibm_db');
const connectQuery =
'DATABASE=' +
DATABASE +
';HOSTNAME=' +
HOSTNAME +
';UID=' +
UID +
';PWD=' +
PWD +
';PORT=' +
PORT +
';PROTOCOL=TCPIP';
ibmdb.open(connectQuery, function(err, conn) {
if (err) return console.log(err);
conn.query('select 1 from sysibm.sysdummy1', function(err, data) {
if (err) console.log('err');
else console.log('data');
conn.close(function() {
console.log('done');
});
});
});
Error:
Error: Could not locate the bindings file. Tried:
→ ...\node_modules\ibm_db\build\odbc_bindings.node
→ ...\node_modules\ibm_db\build\Debug\odbc_bindings.node
→ ...\node_modules\ibm_db\build\Release\odbc_bindings.node
→ ...\node_modules\ibm_db\out\Debug\odbc_bindings.node
→ ...\node_modules\ibm_db\Debug\odbc_bindings.node
Is there any other node package to establish connection ?
I have the same issue on windows 10. Because your ibm_db module is not installed successfully.
Download directly clidriver generated by IBM. After setting IBM_DB_HOME environment variable to point the directory, and reinstall ibm_db module to skip downloading clidriver.
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.
My protractor test cases randomly fail with this error message:
Failed: ECONNREFUSED connect ECONNREFUSED 127.0.0.1
I have gone through the resources and tried all the suggested solutions:
Upgraded protractor
Ran webdriver-manager update
Upgraded chromedriver version but the issue seems to exist.
This particularly happens when I try to run all the e2e tests together.
Below is the specific versions that Im using for my project:
node - v9.2.0
protractor - Version 5.4.1
ChromeDriver 2.42.591088
Please help.
Thanks,
Neeraja
Are you using async/await in your tests?
Can you try applying patch as specified below from the same folder which contains the 'node_modules' folder by executing 'node patch.js'?
patch.js file
var fs = require('fs');
var httpIndexFile = 'node_modules/selenium-webdriver/http/index.js';
fs.readFile(httpIndexFile, 'utf8', function (err, data) {
if (err)
throw err;
var result = data.replace(/\(e.code === 'ECONNRESET'\)/g, "(e.code === 'ECONNRESET' || e.code === 'ECONNREFUSED')");
console.log(`Patching ${httpIndexFile}`)
fs.writeFileSync(httpIndexFile, result, 'utf8');});
var chromeFile = 'node_modules/selenium-webdriver/chrome.js';
fs.readFile(chromeFile, 'utf8', function (err, data) {
if (err)
throw err;
var result = data.replace(/new http.HttpClient\(url\)/g, "new http.HttpClient(url, new (require('http').Agent)({ keepAlive: true }))");
console.log(`Patching ${chromeFile}`)
fs.writeFileSync(chromeFile, result, 'utf8');});
Please see original post here -
https://github.com/angular/protractor/issues/4706#issuecomment-393004887
I'm trying to connect to my mongodb using nodejs and socket.io. I am able to connect to the database because I get 'connection accepted' in my console but on the nodejs side, as soon as I - indeed - get
Connection to mongodb://localhost:27017 established through mongoose
it immediately fails next with
process.nextTick(function() { throw err; }) ^TypeError: undefined is
not a function at showCollections**
And here goes showCollections:
var showCollections = function(db, callback) {
mongoose.connection.db.collectionNames(function(error, names) {
if (error) {
throw new Error(error);
} else {
console.log("=>Listening mongo collections:");
names.map(function(cname) {
mongoose.connection.db.dropCollection(cname.name);
console.log("--»"+cname.name);
});
}
});
}
And here is the content of my database folder:
_tmp (empty folder)
local.0
local.ns
mongod.lock
I run the mongodb by typing mongod --dbpath folder and it successfully 'awaits connections on port 27017'.
Also, my node_modules from package.json (npm)
"dependencies": {
"express": "^4.9.6",
"socket.io": "latest",
"mongodb": "~2.0",
"mongoose": "*"
}
Thank you very much for your help...
StackTrace:
> TypeError: undefined is not a function
> at showCollections (/usr/share/nginx/www/index.js:77:25)
> at NativeConnection.callback (/usr/share/nginx/www/index.js:46:3)
> at NativeConnection.g (events.js:199:16)
> at NativeConnection.emit (events.js:104:17)
> at open (/usr/share/nginx/www/node_modules/mongoose/lib/connection.js:485:10)
> at NativeConnection.Connection.onOpen (/usr/share/nginx/www/node_modules/mongoose/lib/connection.js:494:5)
> at /usr/share/nginx/www/node_modules/mongoose/lib/connection.js:453:10
> at /usr/share/nginx/www/node_modules/mongoose/lib/drivers/node-mongodb-native/connection.js:59:5
> at /usr/share/nginx/www/node_modules/mongoose/node_modules/mongodb/lib/db.js:200:5
> at connectHandler (/usr/share/nginx/www/node_modules/mongoose/node_modules/mongodb/lib/server.js:272:7)
EDIT:
I'm as well having these problems when trying to run the nodejs instance:
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
js-bson: Failed to load c++ bson extension, using pure JS version
I tried fixing them as other questions here would tell but nothing worked either...
From the provided information, it looks like you are using mongodb 2.0 driver. The db.collectionNames method was dropped. Check out the "Db Object" section of this page - https://github.com/mongodb/node-mongodb-native/blob/0642f18fd85037522acf2e7560148a8bc5429a8a/docs/content/tutorials/changes-from-1.0.md#L38
They've replaced it with listCollections. You should get the same effect with:
mongoose.connection.db.listCollections().toArray(function(err, names) {
if (err) {
console.log(err);
}
else {
names.forEach(function(e,i,a) {
mongoose.connection.db.dropCollection(e.name);
console.log("--->>", e.name);
});
}
});
For me this error started popping up when i had to force shut down my pc as it became unresponsive. Next time i started my express server this error popped up. I solved it by running npm install mongoose#4.0 --save in the terminal.
May be this error pops up when your server or database is force closed and some code is not save in mongod behind the scenes.
Shouldn't you specify the full path and have an export module?...something like:
mongoose.connection.db.collectionNames(function (err, names)
{
console.log(names); // [{ name: 'dbname.myCollection' }]
module.exports.Collection = names;
}
If I'm wrong it's because I don't fancy moongodb :)
Am a new user of MonogoDB n Nodejs. Building a simple product catalogue. Trying to import CSV file contents to mongodb. I got Syntax error:: Unexpected identifier error: Is there any way to resolve this?
I am curious to know about using ya-csv package available on Git. Can anyone help?
Try as below:
npm install ya-csv //install package
//Put this code in your .js file
var csv = require("ya-csv");
var validRows = [];
var reader = csv.createCsvFileReader("/csv/file.csv", {columnsFromHeader:true,'separator': ',' , encoding: "utf8"});
reader.addListener('data', function(data) { //if rows are in correct format then it will push into array
if(data){
validRows.push(data);
}
});
reader.addListener('end', function(){ //this method will be called after reading all csv rows
validRows.forEach(function(data){
//console.log(data.name); //get your data like this
});
});
reader.addListener('error', function(err){
console.log(err); //if any error occurred
});
For further detail please follow this link
https://github.com/koles/ya-csv