There is an error in running mysql (node.js) file in cmd - mysql

There is an error in running mysql (node.js) file in cmd. It is showing module not found...
What is the problem occurring?
Please help....
The error:-
C:\Users\mhars>node trial.js
node:internal/modules/cjs/loader:926
throw err;
^
Error: Cannot find module 'C:\Users\mhars\trial.js'
←[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:923:15)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:768:27)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)←[39m
←[90m at node:internal/main/run_main_module:17:47←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: []
}

Related

TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider');

let provider = new ethers.providers.JsonRpcProvider(url);
^
TypeError: Cannot read properties of undefined (reading 'JsonRpcProvider')
at Object. (e:\Error\readblockchain.js:12:37)
←[90m at Module._compile (node:internal/modules/cjs/loader:1159:14)←[39m
←[90m at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)←[39m
←[90m at Module.load (node:internal/modules/cjs/loader:1037:32)←[39m
←[90m at Module._load (node:internal/modules/cjs/loader:878:12)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)←[39m
←[90m at node:internal/main/run_main_module:23:47←[39m
Node.js v18.12.1
PS E:\Error>See The Image-->>
Had the same problem few days ago, turned out to be problem with a beta release of ethers.js.
The fix for me was to downgrade "ethers" to version 5.4 in the package.json, then folder and lastly npm install to install ethers again.
Step 1 :in package.json
{
"dependencies": {
"ethers": "5.4" <<<<<-------------
}
}
Step 2 : Delete node_modules
Step 3 : npm install

Error: Invalid JSON RPC response: undefined

During the install of this github project I get this error:
Error: Invalid JSON RPC response: undefined
at Object.InvalidResponse (C:\Users\backu\blockchain\Blockchain4LinkedData-master\Dapp\node_modules\web3\lib\web3\errors.js:35:16)
at HttpProvider.send (C:\Users\backu\blockchain\Blockchain4LinkedData-master\Dapp\node_modules\web3\lib\web3\httpprovider.js:91:22)
at RequestManager.send (C:\Users\backu\blockchain\Blockchain4LinkedData-master\Dapp\node_modules\web3\lib\web3\requestmanager.js:58:32)
at Eth.send [as getBlock] (C:\Users\backu\blockchain\Blockchain4LinkedData-master\Dapp\node_modules\web3\lib\web3\method.js:145:58)
at Object. (C:\Users\backu\blockchain\Blockchain4LinkedData-master\Dapp\app\routes.js:31:22)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
Could someone help me with this?
Most likely, when the geth was launched, one of the modules whose methods were used by Dapp was not enabled in the settings of the RPC API. Look at the value of the --rpcapi key from the startup line.

getting 500 response in Browsershot

I'm getting 500 response code from browsershot package
<?php
// Report all errors
error_reporting(E_ALL);
ini_set('display_errors', 1);
include_once('vendor/autoload.php');
use Spatie\Browsershot\Browsershot;
// an image will be saved
Browsershot::url('https://google.com')->save('example.pdf');
?>
Fatal error: Uncaught
Symfony\Component\Process\Exception\ProcessFailedException: The
command "PATH=$PATH:/usr/local/bin NODE_PATH=npm root -g node
'/home/www/html/developementsec.com/browsershotnew/src/../bin/browser.js'
'{"url":"https://google.com","action":"pdf","options":{"path":"example.pdf","args":[],"viewport":{"width":800,"height":600}}}'"
failed. Exit Code: 8(Unknown error) Working directory:
/home/www/html/developementsec.com/browsershotnew Output:
================ Error Output: ================ /usr/lib/node_modules/npm/lib/config/cmd-list.js:113
module.exports.aliases = Object.assign({}, shorthands, aaffordances) ^
TypeError: Object function Object() { [native code] } has no method
'assign' at Object.
(/usr/lib/node_modules/npm/lib/config/cmd-list.js:113:33) 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 (modul in
/home/www/html/developementsec.com/browsershotnew/src/Browsershot.php
on line 663

node.js MySQL connection not established - only when using XAMPP

I'm trying to establish a MySQL connection with my node.js server, but when I do, I get the following error:
F:\Programmering\nodejs-server>node dbConnection.js
F:\Programmering\nodejs-server\dbConnection.js:10
if (err) throw err;
^
Error: connect ECONNREFUSED 127.0.0.1:3306
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1198:14)
--------------------
at Protocol._enqueue (F:\Programmering\nodejs-server\node_modules\mysql\lib\
protocol\Protocol.js:145:48)
at Protocol.handshake (F:\Programmering\nodejs-server\node_modules\mysql\lib
\protocol\Protocol.js:52:23)
at Connection.connect (F:\Programmering\nodejs-server\node_modules\mysql\lib
\Connection.js:130:18)
at Object.<anonymous> (F:\Programmering\nodejs-server\dbConnection.js:9:5)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
I've tried using other ports, but still same error message. When I use XAMPP, and start MySQL service, it connects fine. These are the messages when I install mysql using npm:
F:\Programmering\nodejs-server>npm install mysql
npm WARN nodejs-server#1.0.0 No repository field.
+ mysql#2.15.0
added 11 packages in 7.809s
I have been using the w3schools tutorial. This is my code:
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "myusername",
password: "mypassword"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
What am I doing wrong? Please help! Thank you!

Establishing a connection between Node.js and MySQL

I'm a complete newbie to Node.js, but I do have some experience with mysql and some other languages.
I am trying to establish a database connection between Node.js and MySQL, however, my terminal keeps on giving me errors. It failed, so I tried to debug it by using "error.stack" as stated from the documentation, that failed also so I'm totally lost now. Can someone please help me to figure out the bug.
Also, can anyone also tell me how to tell Node.js to print out the reason of why it failed to connect to the database like the function "mysql_error()" from PHP.
My original Node.js code:
var MySQL = require('mysql');
var DatabaseConnection = MySQL.createConnection({
host: '10.0.0.25',
user: 'Admin',
password: 'Password'
});
DatabaseConnection.connect(function(error) {
if(!error) {
console.log("Database is connected");
return;
} else {
console.log("Database is not connected: ");
console.log(error.stack);
}
});
My result:
Database is not connected:
Error: connect ECONNREFUSED 10.0.0.25:3306
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
--------------------
at Protocol._enqueue (/Users/marc/Documents/JSON_MySQL_Database_Test/node_modules/mysql/lib/protocol/Protocol.js:145:48)
at Protocol.handshake (/Users/marc/Documents/JSON_MySQL_Database_Test/node_modules/mysql/lib/protocol/Protocol.js:52:23)
at Connection.connect (/Users/marc/Documents/JSON_MySQL_Database_Test/node_modules/mysql/lib/Connection.js:130:18)
at Object.<anonymous> (/Users/marc/Documents/JSON_MySQL_Database_Test/Database_Test.js:8:20)
at Module._compile (module.js:643:30)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Function.Module.runMain (module.js:684:10)