I am getting the following error while connecting to the MongoDB through Node.js.
Error:
process.nextTick(function() { throw err; })
^
Error: connect UNKNOWN 127.0.0.1:27017 - Local (undefined:undefined)
at Object.exports._errnoException (util.js:870:11)
at exports._exceptionWithHostPort (util.js:893:20)
at connect (net.js:843:14)
at net.js:939:9
at doNTCallback0 (node.js:419:9)
at process._tickCallback (node.js:348:13)
I am running the my MongoDB using the command mongod --dbpath C:\new --journal.I am explaining my code below.
var mongo=require('mongojs');
var database='medilink';
var collections=['admin','supplier'];
var db=mongo("localhost:27017/"+database, collections);
Here i have one login app.When user is trying to login the above error is coming.Please help me to resolve this error.
Related
So mongoose was working just fine for more than 2 months, but suddenly crashed with this error
/home/container/node_modules/mongodb/lib/cmap/connection.js:210
callback(new error_1.MongoServerError(document));
^
MongoServerError: bad auth : Authentication failed.
at Connection.onMessage (/home/container/node_modules/mongodb/lib/cmap/connection.js:210:30)
at MessageStream.<anonymous> (/home/container/node_modules/mongodb/lib/cmap/connection.js:63:60)
at MessageStream.emit (node:events:527:28)
at processIncomingData (/home/container/node_modules/mongodb/lib/cmap/message_stream.js:132:20)
at MessageStream._write (/home/container/node_modules/mongodb/lib/cmap/message_stream.js:33:9)
at writeOrBuffer (node:internal/streams/writable:390:12)
at _write (node:internal/streams/writable:331:10)
at MessageStream.Writable.write (node:internal/streams/writable:335:10)
at TLSSocket.ondata (node:internal/streams/readable:777:22)
at TLSSocket.emit (node:events:527:28) {
ok: 0,
code: 8000,
codeName: 'AtlasError',
[Symbol(errorLabels)]: Set(1) { 'HandshakeError' }
}
Anyone knows what is the issue?
My IP is configured as access from anywhere correctly
Using connection to application, my uri is well configured and copy pasted to my project, and again the connection was perfect for 2months but stopped out of nowhere
MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017
if i reinstall mongodb,the code works fine. i wanted an permenant solution
c[error:MongoNetworkError: failed to connect to server [localhost:27017] on first connect [Error: connect ECONNREFUSED 127.0.0.1:27017 ]
const mongoClient=require("mongodb").MongoClient
const state={
db:null
}
module.exports.connect=function(done){
const url="mongodb://localhost:27017"
const dbname="r-kart"
mongoClient.connect(url,(err,data)=>{
if(err) return done(err)
state.db=data.db(dbname)
done()
})
}
module.exports.get=function(){
return state.db
}
I'm learning Sails JS (and NodeJS), and I'm trying to set a connection to SQL Server Express. What I have so far:
A database called test-project-db with a table inside called TestTable1. It has two columns: name varchar(20) and description varchar(100).
A sails project generated with sails new, and a model/component made with sails generate api TestTable1.
My files:
- api/models/TestTable1.js
module.exports = {
attributes: {
name: {
type: 'string',
},
description: {
type: 'string',
},
}
};
- config/connections.js:
sqlserver: {
adapter : 'sails-sqlserver',
user : 'sa',
password: 'passw',
host : 'localhost\\SQLEXPRESS',
database: 'test-project-db'
}
- config/models.js:
module.exports.models = {
connection: 'sqlserver',
migrate: 'safe',
};
But when I run the server with sails lift and go to localhost:1337/testtable1, I get the error:
(node:15756) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): ConnectionError: Failed to connect to localhost:undefined in 60000ms
(node:15756) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
And, if instead of sails-sqlserver I use sails-mssqlserver, I get (in the console):
{"name":"Sails-MSSqlserver","hostname":"DESKTOP-PMN0K03","pid":15928,"level":30,"msg":"Error in __FIND__: { ConnectionError: Failed to connect to localhost:undefined in 60000ms\n at Connection.<anonymous> (D:\\Práctica 2\\test-project\\node_modules\\sails-mssqlserver\\node_modules\\mssql\\lib\\tedious.js:378:25)\n at Object.onceWrapper (events.js:315:30)\n at emitOne (events.js:116:13)\n at Connection.emit (events.js:211:7)\n at Connection.connectTimeout
(D:\\Práctica 2\\test-project\\node_modules\\sails-mssqlserver\\node_modules\\tedious\\lib\\connection.js:467:12)\n at ontimeout (timers.js:475:11)\n at tryOnTimeout (timers.js:310:5)\n at Timer.listOnTimeout (timers.js:270:5)\n name: 'ConnectionError',\n message: 'Failed to connect to localhost:undefined in 60000ms',\n code: 'ETIMEOUT' }","time":"2018-01-31T19:00:27.325Z","v":0}
error: Sending 500 ("Server Error") response:
Error (E_UNKNOWN) :: Encountered an unexpected error
ConnectionError: Failed to connect to localhost:undefined in 60000ms
at Connection.<anonymous> (D:\Práctica 2\test-project\node_modules\sails-mssqlserver\node_modules\mssql\lib\tedious.js:378:25)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:116:13)
at Connection.emit (events.js:211:7)
at Connection.connectTimeout (D:\Práctica 2\test-project\node_modules\sails-mssqlserver\node_modules\tedious\lib\connection.js:467:12)
at ontimeout (timers.js:475:11)
at tryOnTimeout (timers.js:310:5)
at Timer.listOnTimeout (timers.js:270:5)
Details: ConnectionError: Failed to connect to localhost:undefined in 60000ms
And in the browser:
[Error (E_UNKNOWN) Encountered an unexpected error] Details: ConnectionError: Failed to connect to localhost:undefined in 60000ms
Along a 500 error page.
Any idea on what am I doing wrong?
localhost:undefined --> The port is undefined because you didn't provide it in the configuration. Add in the port attribute into your sqlserver connection within config/connections.js, and assign it your database server's port.
Side note: learning Sails while learning Node is quite a handful, especially since Sails can look intimidating at first. Just take it piece by piece, and you'll definitely get a hang of it. If you're familiar with MVC frameworks, such as Rails, then Sails will feel right at home.
Before posting this question I went through a couple of SO posts with the same heading. All of them suggested me to restart my app..I tried that but I am still getting the error.
The code that is throwing the error is
app.post('/insert', function(request, response) {
var connection = mySequel.createConnection(ConnectionParams);
connection.connect();
var UserName = request.body.UserName;
// insert into userrecords values ("123456",DEFAULT,DEFAULT,DEFAULT,10);
var InsertQuery = "insert into userrecords values (" + UserName + ",DEFAULT,DEFAULT,DEFAULT,-10);";
connection.query(InsertQuery, function(error, result, fields) {
if (error) {
response.send("error");
console.log(error);
throw error;
} else {
// response.send("success");
console.log(result.insertId);
response.send(result.insertId);
}
});
connection.end();
});
The error caused by the code is this
events.js:160
2017-04-26T11:42:52.410094+00:00 app[web.1]:
2017-04-26T11:42:52.410092+00:00 app[web.1]: throw er; // Unhandled 'error' event
2017-04-26T11:42:52.410096+00:00 app[web.1]: Error: Quit inactivity timeout
2017-04-26T11:42:52.410097+00:00 app[web.1]: at Quit.<anonymous> (/app/node_modules/mysql/lib/protocol/Protocol.js:160:17)
2017-04-26T11:42:52.410093+00:00 app[web.1]: ^
2017-04-26T11:42:52.410098+00:00 app[web.1]: at emitNone (events.js:86:13)
2017-04-26T11:42:52.410099+00:00 app[web.1]: at Quit._onTimeout (/app/node_modules/mysql/lib/protocol/sequences/Sequence.js:127:8)
2017-04-26T11:42:52.410099+00:00 app[web.1]: at Quit.emit (events.js:185:7)
2017-04-26T11:42:52.410100+00:00 app[web.1]: at ontimeout (timers.js:380:14)
2017-04-26T11:42:52.410101+00:00 app[web.1]: at tryOnTimeout (timers.js:244:5)
2017-04-26T11:42:52.410102+00:00 app[web.1]: at Timer.listOnTimeout (timers.js:214:5)
I am hosting my app on Heroku and whenever I try to access this URL the app is crashing forcing me to restart the dyno. The data I am sending is being successfully inserted into the DB but the auto incremented primary key is not being returned to my app. Instead I get a server error.
JSON.stringify() returns the correct value once and after that the app crashed which maked the subsequent requests to fail.
How can I solve this problem?
Try converting your response into JSON before sending it.
Like
response.send(JSON.stringify(result.insertId));
I too once had a similar problem and I think that is how I solved it.
EDIT:
I went through the myql npm library and found something called Pool. Pool is used when you app needs to handle more than one request at a time. I suggest that you try that. There is a good example availble here.
I have same problem, i just downgrade to react-scripts#2.1.8
this is the steps:
cd my-app
npm install react-scripts#2.1.8
npm start
I'm currenlty working on a TS3 query bot written in node.js.
I added an auto reconnect to it but I have the issue now that the bot crashes if the server is offline with the following error:
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:983:19)
The line which starts the connection is the following:
var cl = new ts3.TeamSpeakClient(config.serverIP);
used with the node-ts api -> https://github.com/nikeee/node-ts
I already added the following events:
cl.on('error', function(err){
console.log("bla: " + err)
});
cl.on('uncaughtException', function (err) {
console.log(err);
});
uncaughtException doesn't get triggered and error doesn't prevent the crash.
How can I prevent it from crashing?
Edit: It's async btw.
You need to catch the UncaughtException on the process rather than in ts3 object.
process.on('uncaughtException', function (err) {
console.log(err);
})
More on handling exceptions can be found over here.
UPDATE:
cl has its own fail promise as well. To be implemented like this:
cl.fail(function(err) {
console.log("An error occurred." + util.inspect(err))
});