Connection refused while connection elasticsearch in node - node.js

I am using node version 0.10.33 and elasticsearch version 3.0.0 but i am not able to connect to elasticsearch.
http://localhost:9200/
Elasticsearch ERROR: 2014-11-25T16:30:16Z
Error: Request error, retrying -- connect ECONNREFUSED
at Log.error (/Users/shank/Documents/MyUmpa/Server/node_modules/elasticsearch/src/lib/log.js:213:60)
at checkRespForFailure (/Users/shank/Documents/MyUmpa/Server/node_modules/elasticsearch/src/lib/transport.js:195:18)
at HttpConnector.<anonymous> (/Users/shank/Documents/MyUmpa/Server/node_modules/elasticsearch/src/lib/connectors/http.js:146:7)
at ClientRequest.bound (/Users/shank/Documents/MyUmpa/Server/node_modules/elasticsearch/node_modules/lodash-node/modern/internals/baseBind.js:56:17)
at ClientRequest.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1551:9)
at Socket.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:419:13)
Trace: elasticsearch cluster is down!
at app.post.resturantController.ResturantInfo.name (/Users/shank/Documents/MyUmpa/Server/app.js:32:13)
at respond (/Users/shank/Documents/MyUmpa/Server/node_modules/elasticsearch/src/lib/transport.js:254:9)
at sendReqWithConnection (/Users/shank/Documents/MyUmpa/Server/node_modules/elasticsearch/src/lib/transport.js:174:7)
at next (/Users/shank/Documents/MyUmpa/Server/node_modules/elasticsearch/src/lib/connection_pool.js:213:7)
at process._tickCallback (node.js:419:13)

Have you run elastic search server? If not then Download Elasticsearch and unzip it into whatever directory you like. Next, open a terminal, cd to the directory you just unzipped, and run bin/elasticsearch (bin/elasticsearch.bat on Windows). After running elasticsearch server, run the node server!

Related

MongoDB error while installing Rocket.chat in CentOS 8 server with Apache

I am following this tutorial to install a Rocket.chat server in CentOS:
https://hostpresto.com/community/tutorials/how-to-install-rocket-chat-server-on-centos-7/
I am new to mongodb and node.js so I am not very familiar with how all this works
At the moment I am looking for something simple that just works
When I reach the step where it says to execute
node main.js
I get the following error:
[username#localhost Rocket.chat]$ node main.js
/opt/Rocket.chat/programs/server/node_modules/fibers/future.js:313
throw(ex);
^
MongoError: not master and slaveOk=false
at Connection.<anonymous> (/opt/Rocket.chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/pool.js:450:61)
at Connection.emit (events.js:310:20)
at processMessage (/opt/Rocket.chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connection.js:384:10)
at Socket.<anonymous> (/opt/Rocket.chat/programs/server/npm/node_modules/meteor/npm-mongo/node_modules/mongodb/lib/core/connection/connection.js:553:15)
at Socket.emit (events.js:310:20)
at addChunk (_stream_readable.js:286:12)
at readableAddChunk (_stream_readable.js:268:9)
at Socket.Readable.push (_stream_readable.js:209:10)
at TCP.onStreamRead (internal/stream_base_commons.js:186:23) {
ok: 0,
errmsg: 'not master and slaveOk=false',
code: 13435,
codeName: 'NotMasterNoSlaveOk',
[Symbol(mongoErrorContextSymbol)]: {}
}
The tutorial says I should be able to see the Rocket.chat web interface if I go to https://yourdomain.com:3000 but I get an unable to connect page, which I suppose is due to the error above
The tutorial also says node main.js is to check if MongoDB is running or not. I can see that MongoDb service is running by executing
systemctl status mongod
so this error seems to be caused by something else.
How do I find out what is causing this error? Or are there any mistakes in this tutorial? I have found other tutorials regarding installing Rocket.chat in CentOS but most of them use nginx as hte web server while I need to use Apache.

MongoDB refuses Connection on Windows 10 machine

i'm running a Node.js app on my Windows 10 machine. I have Mongoose installed and setup like this:
// Init Database
var mongoose = require("mongoose");
var mongoDB = "mongodb://127.0.0.1/sampledata"
mongoose.connect(mongoDB);
var db = mongoose.connection;
// Check DB connection
db.once("open", function(){
console.log("Connected to MongoDB");
});
// Check for DB errors
db.on("error", function(err){
console.log(err);
});
Now, when I start the server with nodemon, the following error appears in the console:
{ MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
at Pool.<anonymous> (C:\Users\...\node_modules\mongodb-core\lib\topologies\server.js:564:11)
at emitOne (events.js:96:13)
at Pool.emit (events.js:188:7)
at Connection.<anonymous> (C:\Users\...\node_modules\mongodb-core\lib\connection\pool.js:317:12)
at Connection.g (events.js:291:16)
at emitTwo (events.js:106:13)
at Connection.emit (events.js:191:7)
at Socket.<anonymous> (C:\...\node_modules\mongodb-core\lib\connection\connection.js:246:50)
at Socket.g (events.js:291:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1278:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ]
}
When I try to start mongo over the console, I get the following error:
C:\Program Files\MongoDB\Server\4.0\bin>mongo
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
2018-10-03T19:05:24.194+0200 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Es konnte keine Verbindung hergestellt werden, da der Zielcomputer die Verbindung verweigerte (in english: A connection couldn't be established, because the target computer has refused the connection). :
connect#src/mongo/shell/mongo.js:257:13
#(connect):1:6
exception: connect failed
I've never encountered this error before and as stupid as it sounds, yesterday everything worked fine. Haven't changed the code or anything, so it must be an issue with my computer I guess.
Do you guys know what could cause this error?
TL;DR
Start mongod server
mongod
Open another terminal window
Start mongo shell
mongo
Longer Version:
Open Command prompt as an administrator and run netstat -anb, check which port mongodb is listening to (Usually 27017). If you dont see a listing for mongo then it means that mongod is not running, so go ahead and start mongod.exe from the mongodb binaries(or if environment variables are set, run mongod from anywhere on your cmd).
if this doesnt work, your firewall is probably blocking access on that port, so check that out
I was getting this error as well. In my case, I was trying to upgrade to MongoDB 4.0 without first upgrading to 3.6.
Please see https://docs.mongodb.com/manual/release-notes/4.0/#upgrade-procedures if you recently updated MongoDB.

No living connections Error while Elasticsearch connections in nodejs

I am having this problem while connecting the elasticsearch connections.
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({ host: 'localhost:9200',
log: 'trace'});
Elasticsearch ERROR: 2016-07-19T19:09:26Z
Error: Request error, retrying -- connect ECONNREFUSED 127.0.0.1:9200
at Log.error (/root/git_build/FirstMoveChess/node_modules/elasticsearch/src/lib/log.js:225:56)
at checkRespForFailure (/root/git_build/FirstMoveChess/node_modules/elasticsearch/src/lib/transport.js:195:18)
at HttpConnector. (/root/git_build/FirstMoveChess/node_modules/elasticsearch/src/lib/connectors/http.js:154:7)
at ClientRequest.bound (/root/git_build/FirstMoveChess/node_modules/lodash-node/modern/internals/baseBind.js:56:17)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at Socket.socketErrorListener (_http_client.js:308:9)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1272:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
Elasticsearch TRACE: 2016-07-19T19:09:27Z
-> HEAD http://localhost:9200/
I understand this question is quite old but I wanted to share how you can solve this problem.
If you are locally using elasticsearch
First thing you must do is running elasticsearch on your machine.
Error: Request error, retrying -- connect ECONNREFUSED 127.0.0.1:9200
Because above message indicates that you're not running elasticsearch locally.
So, visit the link and follow the insturction.
Docker environment
It gets much trickier here.
First, follow the instruction here.
And in case you're using node.js elasticsearch client, you have to specify elasticsearch host as 172.24.0.1.
If you use container_name or private IP of container in docker-compose.yml, it won't work.
In case of Docker Container Environment after changing from http://localhost:9200 to http://ipaddress:9200 in docker-compose.yml
please change the following live in docker-compose.yml that is related to CORS
Change this
** http.cors.allow-origin=/https?://localhost(:[0-9]+)?/ **
into this
*- http.cors.allow-origin= **

My meanjs Application is not getting started in offline mode?

I have installed all the prerequisites for a mean application(MEAN) as described in Meanjs Official website
I want you to look at this particular error I am getting and that too when I am offline.
But it does work well when I am connected to internet.
Help me Try looking at the error below:
Could not connect to MongoDB!
Error: failed to connect to [localhost:27017]
C:\Users\ASHOK\Downloads\meanjs-mean-88a89f2\node_modules\connect-mongo\lib\connect-mongo.js:186
throw err;
^
Error: Error connecting to database: failed to connect to [localhost:27017]
at null.<anonymous> (C:\Users\ASHOK\Downloads\meanjs-mean-88a89f2\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\server.js:555
:25)
at emit (events.js:118:17)
at null.<anonymous> (C:\Users\ASHOK\Downloads\meanjs-mean-88a89f2\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection_po
ol.js:156:15)
at emit (events.js:110:17)
at Socket.<anonymous> (C:\Users\ASHOK\Downloads\meanjs-mean-88a89f2\node_modules\mongoose\node_modules\mongodb\lib\mongodb\connection\connection.
js:534:10)
at Socket.emit (events.js:107:17)
at net.js:950:16
at process._tickCallback (node.js:355:11)
[nodemon] app crashed - waiting for file changes before starting...
Did you start mongodb: try typing mongod into the terminal

Starting node-huxley with example tests

I'm struggling to get node-huxley to run. Having installed it globally, I then installed the node-selenium driver, cloned the repo and tried to run Huxley on the examples. However I'm seeing this error.
It seems to suggest that the server isn't running, but I've verified it as running on localhost:8000 correctly. Any ideas how to debug this?
firefox opening.
At 1 type and toggle.hux
/usr/local/lib/node_modules/huxley/node_modules/selenium-webdriver/lib/webdriver/promise.js:1549
throw error;
^
Error: ECONNREFUSED connect ECONNREFUSED
at ClientRequest.<anonymous> (/usr/local/lib/node_modules/huxley/node_modules/selenium-webdriver/http/index.js:127:16)
at ClientRequest.EventEmitter.emit (events.js:95:17)
at Socket.socketErrorListener (http.js:1547:9)
at Socket.EventEmitter.emit (events.js:95:17)
at net.js:440:14
at process._tickCallback (node.js:415:13)
==== async task ====
WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_ (/usr/local/lib/node_modules/huxley/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:49)
at Function.webdriver.WebDriver.createSession (/usr/local/lib/node_modules/huxley/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:111:30)
at Builder.build (/usr/local/lib/node_modules/huxley/node_modules/selenium-webdriver/builder.js:105:20)
at _open (/usr/local/lib/node_modules/huxley/source/browser/driver.js:28:6)
at Object.open (/usr/local/lib/node_modules/huxley/source/browser/driver.js:49:3)
at _openRunAndClose (/usr/local/lib/node_modules/huxley/index.js:76:11)
at /usr/local/lib/node_modules/huxley/index.js:169:5
at /usr/local/lib/node_modules/huxley/index.js:217:5
at /usr/local/lib/node_modules/huxley/source/playback/getPlaybackInfos.js:121:5
Have you started selenium? (https://github.com/chenglou/node-huxley#installation)

Resources