Connection bug with socket.io-client (Server to Server) - node.js

I have a problem with socket.io-client normaly when i connect my clientWS to the ServerWS it try to connect in loop even if the ServerWS is not started.
I tried it in a simple node app and it work, but when I'm trying to include it in another project i got this error:
.../node_modules/socket.io-client/lib/manager.js:75
this.nsps[nsp].emit.apply(this.nsps[nsp], arguments);
^
TypeError: Cannot call method 'apply' of undefined
at Manager.emitAll (.../node_modules/socket.io-client/lib/manager.js:75:25)
at null._onTimeout (.../node_modules/socket.io-client/lib/manager.js:464:12)
at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)
16 Mar 21:54:03 - [nodemon] app crashed - waiting for file changes before starting...
And it's the same connection code in both project :
var socket = require("socket.io-client");
var ws = socket("http://localhost:3000");
So I don't know what is the problem...
(tested with socket.io and socket.io-client 1.3.5)

Related

Node Application Crash when sending request

I have been working on a Node application. When i try to run gulp on application , i am facing this error
throw er; // Unhandled 'error' event
^
TypeError: Cannot read property '_id' of null
at passport.conf.js:366:30
at Array.map (native)
at passport.conf.js:364:37
at D:\boibazar-admin_\node_modules\mongoose\lib\model.js:3932:16
at process.nextTick (D:\boibazar-admin_\node_modules\mongoose\lib\query.js:1456:39)
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickDomainCallback (internal/process/next_tick.js:128:9)
[13:54:26] [nodemon] app crashed - waiting for file changes before starting...
It was working perfectly before my windows update. After updating windows (21H1) the application crash all the time when i try to login the system.
Node version of my Application is 6.17.1 and i am using passport-local authentication.
In fornt-end i am using "angular 4". As a new developer in node.js, can anyone help me to sort it out

How do I use redis in node.js?

I am trying to use redis using this segment of code:
const redis = require('redis');
const client = redis.createClient();
I am getting the following error:
events.js:174
throw er; // Unhandled 'error' event
^
Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
You will need to first install redis on your system. To do so, follow the instructions here.
Then run the following command in your command prompt/terminal:
redis-server
If you want to run redis in the background without having to start it everytime, then you can use:
redis-server --daemonize yes
You can check if your server is running by using the command:
redis-cli set a 3 & redis-cli get a
If this works then your redis server has started successfully.
After this, your previous code should be able to connect to the redis-server provided the server is running on the default port (6379).

Node.JS Redis connect EADDRNOTAVAIL error in Microsoft Azure Web App

I have a Node.js app deployed to a Microsoft Azure Web App and I can't seem to fix the following error:
Application has thrown an uncaught exception and is terminated:
> Error: Redis connection to
> <insertRedisHostNameHere> failed -
> connect EADDRNOTAVAIL
> at errnoException (net.js:670:11)
> at connect (net.js:548:19)
> at Socket.connect (net.js:613:5)
> at Object.<anonymous> (net.js:77:12)
> at RedisClient.create_stream (D:\home\site\wwwroot\node_modules\redis\index.js:218:31)
> at new RedisClient (D:\home\site\wwwroot\node_modules\redis\index.js:169:10)
> at Object.createClient (D:\home\site\wwwroot\node_modules\redis\index.js:906:12)
> at Object.<anonymous> (D:\home\site\wwwroot\server.js:8:20)
> at Module._compile (module.js:446:26)
> at Object..js (module.js:464:10)
The code that is causing this error is:
var redis = require('redis');
var client = redis.createClient(17397, '<hostname>', {enable_offline_queue: false});
client.auth('<password>', function(err){
});
client.on('connect', function(){
console.log('connected to redis');
});
I haven't been able to find a working solution, any help is greatly appreciated.
Additionally, I am able to run the same code on my localhost and local Redis cache without any problems at all.
Fixed it by updating the version of Node JS in package.json. (Refer to this question for more details: can't connect to DB - EADDRNOTAVAIL)

Cloud9 + sails.js + phpmyadmin

I have problem with creating basic sails.js application on Cloud9 environment and connecting it to MySQL.
Steps I'm making:
Creating Cloud9 project
installing sails: npm -g install sails
creating project: sails new test
lifting: cd testProject/ and sails lift
Here it's working
Adding mySQL support: mysql-ctl start
still working
adding phpMyAdmin support: phpmyadmin-ctl install
And here, my application stops working. I'm getting exception:
events.js:72
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE
at errnoException (net.js:905:11)
at Server._listen2 (net.js:1043:14)
at listen (net.js:1065:10)
at Server.listen (net.js:1139:5)
at Array.async.auto.start [as 0] (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/lib/hooks/http/start.js:29:35)
at /home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:484:38
at _each (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:46:13)
at Object.async.auto (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:455:9)
at Sails.startServer (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/lib/hooks/http/start.js:16:11)
at Sails.emit (events.js:92:17)
at Sails.emitter.emit (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/lib/app/private/after.js:50:11)
at afterBootstrap (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/lib/app/private/initialize.js:56:11)
at bootstrapDone (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/lib/app/private/bootstrap.js:51:14)
at Object.module.exports.bootstrap (/home/ubuntu/workspace/testProject/config/bootstrap.js:16:3)
at Sails.runBootstrap (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/lib/app/private/bootstrap.js:44:25)
at Sails.bound [as runBootstrap] (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
at Sails.initialize (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/lib/app/private/initialize.js:48:9)
at bound (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/lodash/dist/lodash.js:729:21)
at /home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:607:21
at /home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:246:17
at iterate (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:146:13)
at /home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:157:25
at /home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:248:21
at /home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:612:34
at /home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/lib/app/load.js:201:13
at /home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:451:17
at /home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:441:17
at _each (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:46:13)
at Object.taskComplete (/home/ubuntu/.nvm/v0.10.35/lib/node_modules/sails/node_modules/async/lib/async.js:440:13)
at processImmediate [as _immediateCallback] (timers.js:354:15)
Additionally I'm getting info about problem with starting my app, and ability to kill the process. Of course killing does not help.
Could youplease help me with that?
So what's happening is that you're starting your sails server, which binds to port 8080, and then you try to install phpmyadmin which tries to start apache (at port 8080 too!) causing it to actually fail since the port is already in use. You will have to stop sails before trying to install / run phpmyadmin since two servers can't listen on the same port.

Mongoose Can't Connect Without Internet

I have my MongoDB server running on localhost:27017, and while I can usually run my Node.js app fine, when I disconnect from the internet Mongoose throws the error
Error: failed to connect to [localhost:27017]
Note that I can still connect to the MongoDB server from the Mongo shell client. Also, if I start up my app first and then lose internet connection, my app can access the database fine offline. So why can't it start up without internet?
EDIT: here is the error in full
events.js:85
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
at null.<anonymous> (<My App>\node_modules\mongoose\
node_modules\mongodb\lib\mongodb\connection\server.js:555:74)
at emit (events.js:118:17)
at null.<anonymous> (<My App>\node_modules\mongoose\
node_modules\mongodb\lib\mongodb\connection\connection_pool.js:156:15)
at emit (events.js:110:17)
at Socket.<anonymous> (<My App>\node_modules\mongoos
e\node_modules\mongodb\lib\mongodb\connection\connection.js:534:10)
at Socket.emit (events.js:107:17)
at net.js:923:16
at process._tickCallback (node.js:355:11)
[nodemon] app crashed - waiting for file changes before starting...
Edit: wording
Use 127.0.0.1 instead of localhost. By turning off your wifi interface the OS is no longer able to resolve localhost.
Consider node-offline-localhost.
Add the following before the breaking code:
require('node-offline-localhost').always();
And it just works (hopefully), at least until RFC 3493 gets fixed.
Full disclosure: I authored this package to streamline https in my dev environment when offline.

Resources