Getting Error as "Uncaught Error: getaddrinfo ENOTFOUND xx.xxx.x.112\ABC" while debugging NodeJs Code in Chrome Debugger.
Below are the Server Details:
Server where NodeJs Code resides: xxx.xx.x.100
Server where SQL is installed: xx.xxx.xx.90
Database Server: xx.xxx.x.112\ABC
Database Server Port: 51269.
Below is my NodeJs Code:
var mysql = require('mysql');
debugger
var con = mysql.createConnection({
host: "xx.xxx.x.112\ABC",
user: "sa",
password: "Pass",
port:51269
});
con.connect(function(err) {
if (err)
throw err;
console.log("Connected!");
});
Below is the Error Details:
VM52 trial2.js:11 Uncaught Error: getaddrinfo ENOTFOUND xx.xxx.x.112\ABC
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
--------------------
at Protocol._enqueue (E:\pradeep\Node\SQL_Example\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (E:\pradeep\Node\SQL_Example\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (E:\pradeep\Node\SQL_Example\node_modules\mysql\lib\Connection.js:116:18)
at Object.<anonymous> (E:\pradeep\Node\SQL_Example\trial2.js:10:5)
at Module._compile (internal/modules/cjs/loader.js:773:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)
at internal/main/run_main_module.js:17:11
The Error Message is
function dnsException(code, syscall, hostname)
Also check the below screenshot where Error Message is returning from:
Any suggestions will be highly appreciated, as I am new to NodeJs and scratching my head since last 2-days regarding this issue.
Can you try this below code its working for me so.
Or try with removing port and as you already providing the host server.
var mysql = require('mysql');
debugger
var con = mysql.createConnection(config:{
host: "host_for_connection",
user: "user_name",
password: "paaword",
port: your_portNumber
});
con.connect(function(err) {
if (err)
throw err;
console.log("Connected!");
});
Thank you Nilesh for your help, tried the Shared code but getting new Error messsage now as "Uncaught Error: connect ECONNREFUSED 127.0.0.1:3306".
Tried by both with & without Port.
Note: Nodejs code is in other Machine and Sql is installed in another Machine
Below is the NodeJs Code:
var mysql = require('mysql');
debugger
var con = mysql.createConnection({
config:{
host: "xx.xxx.x.112\ABC",
user: "sa",
password: "Pass",
// port:51269
}
});
con.connect(function(err) {
if (err)
throw err;
console.log("Connected!");
});
Below is the Error Message:
VM52 trial2.js:15 Uncaught Error: connect ECONNREFUSED 127.0.0.1:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1056:14)
--------------------
at Protocol._enqueue (E:\pradeep\Node\SQL_Example\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (E:\pradeep\Node\SQL_Example\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (E:\pradeep\Node\SQL_Example\node_modules\mysql\lib\Connection.js:116:18)
at Object.<anonymous> (E:\pradeep\Node\SQL_Example\trial2.js:12:5)
at Module._compile (internal/modules/cjs/loader.js:773:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:839:10)
at internal/main/run_main_module.js:17:11
exceptionWithHostPort # VM9 errors.js:512
afterConnect # VM81 net.js:1056
TickObject (async)
init # VM43 inspector_async_hook.js:21
emitInitNative # VM21 async_hooks.js:134
emitInitScript # VM21 async_hooks.js:341
TickObject # VM22 task_queues.js:102
nextTick # VM22 task_queues.js:130
(anonymous) # VM72 destroy.js:43
Socket._destroy # VM81 net.js:595
destroy # VM72 destroy.js:37
afterConnect # VM81 net.js:1065
TCPCONNECTWRAP (async)
init # VM43 inspector_async_hook.js:21
emitInitNative # VM21 async_hooks.js:134
internalConnect # VM81 net.js:816
defaultTriggerAsyncIdScope # VM21 async_hooks.js:301
emitLookup # VM81 net.js:978
onlookup # VM156 dns.js:65
GETADDRINFOREQWRAP (async)
init # VM43 inspector_async_hook.js:21
emitInitNative # VM21 async_hooks.js:134
lookup # VM156 dns.js:145
(anonymous) # VM81 net.js:958
defaultTriggerAsyncIdScope # VM21 async_hooks.js:301
lookupAndConnect # VM81 net.js:957
Socket.connect # VM81 net.js:891
connect # VM81 net.js:168
connect # VM55 Connection.js:76
(anonymous) # VM52 trial2.js:12
Module._compile # VM44 loader.js:773
Module._extensions..js # VM44 loader.js:787
Module.load # VM44 loader.js:643
Module._load # VM44 loader.js:556
Module.runMain # VM44 loader.js:839
(anonymous) # VM40 run_main_module.js:17
Related
since 2 weeks I am trying to connect Microsoft SQL server with NodeJS. Please help me out with this
Am available on Instagram : shaziyali8
Thanks in advance
Here is my Code#
const mysql = require("mysql");
const connection = mysql.createConnection({
host: "HP\SQLEXPRESS", // I tried things such as : localhost, Id address: 127.0.0.1, . (a dot)
user: "root",
password: "",
database: "testEmp",
// port: 8889,
});
// console.log(connection);
connection.connect((err) => {
if (err) {
console.log(err);
} else {
console.log("connect");
}
});
Got error
Error: getaddrinfo ENOTFOUND HPSQLEXPRESS
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26)
--------------------
at Protocol._enqueue (F:\NodeJs\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (F:\NodeJs\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (F:\NodeJs\node_modules\mysql\lib\Connection.js:116:18)
at Object.<anonymous> (F:\NodeJs\MySql\index.js:13:12)
at Module._compile (node:internal/modules/cjs/loader:1103:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1155:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'HPSQLEXPRESS',
fatal: true
}
From what I can see, you are trying to connect to a Microsoft SQL server but you are using a MySQL client npm package for the connection. The correct package to connect to a MSSQL server in Node.js is mssql
Install this and check if the connection issue still persists. Also, if the MSSQL server is on your local then using localhost as host name with correct port number would work most of the time.
There are also Connection Strings that you can use to connect to the MSSQL server.
See the documentation here
Hello im trying to run a program thats made in Node.js
the program is called "LawinServer" and i get this error message when trying to run it (worked before idk why it broke never changed any of the code)
edit: i also have admin perms on my pc lol
LawinServer started listening on port 3551
XMPP started listening on port 80
node:events:505
throw er; // Unhandled 'error' event
^
Error: listen EACCES: permission denied 0.0.0.0:80
at Server.setupListenHandle [as _listen2] (node:net:1363:21)
at listenInCluster (node:net:1428:12)
at Server.listen (node:net:1516:7)
at new WebSocketServer (M:\LawinServer-main\node_modules\ws\lib\websocket-server.js:97:20)
at Object.<anonymous> (M:\LawinServer-main\structure\xmpp.js:8:13)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Module._load (node:internal/modules/cjs/loader:827:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
Emitted 'error' event on WebSocketServer instance at:
at Server.emit (node:events:527:28)
at emitErrorNT (node:net:1407:8)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: 'EACCES',
errno: -4092,
syscall: 'listen',
address: '0.0.0.0',
port: 80
}
Node.js v18.2.0
M:\LawinServer-main>pause
Drücken Sie eine beliebige Taste . . .
I tried running the backend server but when I run the command node backend/server.js in my cmd, I'm getting this error:
D:\theshoppingcart>node backend/server.js
events.js:187
throw er; // Unhandled 'error' event
^
Error: listen EACCES: permission denied 8085;
at Server.setupListenHandle [as _listen2] (net.js:1284:19)
at listenInCluster (net.js:1349:12)
at Server.listen (net.js:1448:5)
at Object.<anonymous> (D:\theshoppingcart\backend\server.js:16:8)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11
Emitted 'error' event on Server instance at:
at emitErrorNT (net.js:1328:8)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
code: 'EACCES',
errno: 'EACCES',
syscall: 'listen',
address: '8085;',
port: -1
}
this is my backend/server.js file:
require('dotenv').config()
const express = require("express");
const connectDB = require('./config/db');
connectDB();
const app = express();
const PORT = process.env.PORT || 8085;
app.listen(PORT, ()=> console.log(`server running on port ${PORT}`));
I had the same issue, you should remove the semicolon ; from the .env file. That has worked for me.
Open the .env file and check ";".
PORT = 5050;
You need to remove the ";" from the .env file. make it:
PORT = 5050
I am learning rest api but keep on getting the following error. Why? I am using Node JS, Mongo DB and Express. I am new to this.
Code:
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var mongoose = require('mongoose');
//connect to mongoose
mongoose.connect('mongodb://localost/bookstore');
var db = mongoose.connection;
app.get('/', function(req, res){
res.send('Please use /api for the API.');
});
app.listen(3000);
console.log('Running on port 3000...');
Error:
(node:7908) DeprecationWarning: current URL string parser is deprecated, and wil
l be removed in a future version. To use the new parser, pass option { useNewUrl
Parser: true } to MongoClient.connect.
events.js:183
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE :::3000
at Server.setupListenHandle [as _listen2] (net.js:1360:14)
at listenInCluster (net.js:1401:12)
at Server.listen (net.js:1485:7)
at Function.listen (C:\apiproject\bookstore\node_modules\express\lib\applica
tion.js:618:24)
at Object.<anonymous> (C:\apiproject\bookstore\app.js:14:5)
at Module._compile (module.js:653:30)
at Object.Module._extensions..js (module.js:664:10)
at Module.load (module.js:566:32)
at tryModuleLoad (module.js:506:12)
at Function.Module._load (module.js:498:3)
at Function.Module.runMain (module.js:694:10)
at startup (bootstrap_node.js:204:16)
at bootstrap_node.js:625:3
The error is showing that port 3000 is already in use.
Please get the list of all the ports in use and then kill the port 3000 and run the application again
netstat -a -o to get all the running ports
And then
Taskkill /PID -f (PID)
Hi New Node and I am practising tutorial "makemehapi" In the third assignment I have receiving below error. Any one can point where I am doing wrong?
Regards,
Surya
------------ Code ---------------------
var Path = require('path');
var Hapi = require('hapi');
var Inert = require('inert');
var server = new Hapi.Server();
server.connection({
host: 'localhost',
port: Number(process.argv[2]|| 8080)
});
server.register(require(Inert),function(err){
if(err) throw err;
} )
server.route({
method:'GET',
path:"/index.html",
handler: {
file: "index.html"
}
})
server.start(function () {
console.log('Server running at:', server.info.uri);
});
---------------------- error--------------------------
assert.js:86
throw new assert.AssertionError({
^
AssertionError: path must be a string
at Module.require (module.js:364:3)
at require (module.js:384:17)`enter code here`
at Object.<anonymous> (/home/surya/Desktop/nodeschool/Hapi Practice/test/Lesson3.js:13:17)
at Module._compile (module.js:460:26)
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 Function.Module.runMain (module.js:501:10)
at startup (node.js:129:16)
at node.js:814:3
✗ Error connecting to http://localhost:18384: ECONNREFUSED
events.js:85
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at exports._errnoException (util.js:746:11)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
You are requiring in Inert twice. Remove the require around the Inert variable in the following line:
server.register(require(Inert),function(err){
if(err) throw err;
});
To:
server.register(Inert,function(err){
if(err) throw err;
});