Node.js Error: Unexpected server response: 301 - Running a Node.js Websocket server on Namecheap Webhost - node.js

I'm trying to setup a Node.js Websocket server over at my webhost (Namecheap). However, I am getting this error:
events.js:292
throw er; // Unhandled 'error' event
^
Error: Unexpected server response: 301
at ClientRequest.<anonymous> (D:\****\node_modules\ws\lib\websocket.js:576:7)
at ClientRequest.emit (events.js:315:20)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:596:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
at TLSSocket.socketOnData (_http_client.js:469:22)
at TLSSocket.emit (events.js:315:20)
at addChunk (_stream_readable.js:295:12)
at readableAddChunk (_stream_readable.js:271:9)
at TLSSocket.Readable.push (_stream_readable.js:212:10)
at TLSWrap.onStreamRead (internal/stream_base_commons.js:186:23)
Emitted 'error' event on WebSocket instance at:
at abortHandshake (D:\****\node_modules\ws\lib\websocket.js:694:15)
at ClientRequest.<anonymous> (D:\****\node_modules\ws\lib\websocket.js:576:7)
[... lines matching original stack trace ...]
at TLSSocket.Readable.push (_stream_readable.js:212:10)
The code for the client and server came from here:
https://github.com/websockets/ws#Simple server
https://github.com/websockets/ws#sending-and-receiving-text-data
with ws://www.host.com/path changed to ws://<mydomainname>/<dir1>/<dir2>
Both client and server code runs properly when run locally. Http related code runs properly when used on my webhost. I am trying to get the client code to run locally and connect via websockets to my server hosted at Namecheap.
I suspect something related to the server is preventing connection. I'd ask support but I doubt if they can resolve this. Maybe there's a locked feature or something? Is there something else I could have missed?

Websockets cannot work on Namecheap's hosted servers. Their incoming ports are blocked and cannot be opened for security reasons per their customer's support.
If anyone is looking for a solution just in case, try out a Heroku free account.

Related

Getting read ECONNRESET at TCP.onStreamRead error, while making connection with AZURE server

Hi all I am learning Nodejs. I am uploading file to AZURE server, but getting the below error after every 3-4 minutes. Anyone have the solution for this?
The error is ->
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:111:27)
Emitted 'error' event at:
at Connection._handleProtocolError
(/Data/core/node_modules/mysql/lib/Connection.js:425:8)
at Protocol.emit (events.js:198:13)
at Protocol.EventEmitter.emit (domain.js:448:20)
at Protocol._delegateError
(/Data/core/node_modules/mysql/lib/protocol/Protocol.js:390:10)
at Protocol.handleNetworkError
(/Data/core/node_modules/mysql/lib/protocol/Protocol.js:363:10)
at Connection._handleNetworkError
(/Data/core/node_modules/mysql/lib/Connection.js:420:18)
at Socket.emit (events.js:198:13)
at Socket.EventEmitter.emit (domain.js:448:20)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
"ECONNRESET" means the other side of the TCP conversation abruptly closed its end of the connection. This is most probably due to one or more application protocol errors. You could look at the API server logs to see if it complains about something.
Glad #RakeshSaini that you identified the error which was in the connection waiting limit in the MySQL and for fixing the issue.

NodeJs Unable to make Self Signed Cert work with windows 10

I've been working on this issue on and off for a few months now I am a point where I need this to work. I have solved this issue with git but not nodejs. An Internal url we have is using a Self-Signed cert because its internal use only. I need to use node to communicate with the url. I've tried to set NODE_EXTRA_CA_CERTS many times with nothing working. One way was suggected to set the environemnt value this way
[Environment]::SetEnvironmentVariable("NODE_EXTRA_CA_CERTS", "C:\Temp\NodeCertFix\selfSignedCert.cer", "Machine") I have confirmed that the cert is a base64 cert, same as a .pem in Linux. No Matter what i do i can't get it to work.
events.js:180
throw er; // Unhandled 'error' event
^
Error: unable to get local issuer certificate
at TLSSocket.onConnectSecure (_tls_wrap.js:1317:34)
at TLSSocket.emit (events.js:203:13)
at TLSSocket._finishInit (_tls_wrap.js:792:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:606:12) Emitted 'error' event at:
at TLSSocket.socketErrorListener (_http_client.js:399:9)
at TLSSocket.emit (events.js:203:13)
at emitErrorNT (internal/streams/destroy.js:91:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:59:3)
at processTicksAndRejections (internal/process/task_queues.js:77:11) { code:
'UNABLE_TO_GET_ISSUER_CERT_LOCALLY' }
Did you try the nodejs-self-signed-certificate-example package from npm?

unable to run node js continuously on dedicated windows server

I have a Dedicated windows server, I am running my node express code on the server, but when an exception occurred like
error: remaining connection slots are reserved for non-replication superuser connections
at Connection.parseE (C:\node\zykrrapi\prod\myapp\node_modules\pg\lib\connection.js:554:11)
at Connection.parseMessage (C:\node\zykrrapi\prod\myapp\node_modules\pg\lib\connection.js:381:17)
at TLSSocket.<anonymous> (C:\node\zykrrapi\prod\myapp\node_modules\pg\lib\connection.js:117:22)
at TLSSocket.emit (events.js:180:13)
at addChunk (_stream_readable.js:269:12)
at readableAddChunk (_stream_readable.js:256:11)
at TLSSocket.Readable.push (_stream_readable.js:213:10)
at TLSWrap.onread (net.js:578:20)
Emitted 'error' event at:
at Connection.<anonymous> (C:\node\zykrrapi\prod\myapp\node_modules\pg\lib\client.js:183:19)
at Connection.emit (events.js:180:13)
at TLSSocket.<anonymous> (C:\node\zykrrapi\prod\myapp\node_modules\pg\lib\connection.js:121:12)
at TLSSocket.emit (events.js:180:13)
[... lines matching original stack trace ...]
at TLSWrap.onread (net.js:578:20)
and another error like "too many connections to the user on database" error also occurs and stops the execution of the code. this makes a huge loss of the data for me.
I want to run the Node Js Code continuously and to start the execution again if it stopped unexpectedly.
I am running the code using command "npm start" in windows server...
I want this node code to run only on the windows dedicated server.

Error: certificate has expired in Node

My production node app on Heroku randomly started throwing the following error:
Error: certificate has expired
at Error (native)
at TLSSocket.<anonymous> (_tls_wrap.js:1060:38)
at emitNone (events.js:86:13)
at TLSSocket.emit (events.js:185:7)
at TLSSocket._finishInit (_tls_wrap.js:584:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:416:38)
error: Forever detected script exited with code: 1
error: Script restart attempt #1
Creating a pool connected to blah.thing.com:port
Running migrations for database 'app_name'...
events.js:160
throw er; // Unhandled 'error' event
^
I'm confused by two things. My certificate is up to date, so I don't know why it's saying it's expired, and second, the only two files called "events.js" in my app directory are in two seemingly irrelevant node modules (inquirer and twilio) and don't even have a line 160. What might be the cause of this and how should I even debug it?
edit: In addition, it's just the production app (of course), not staging or local, which is odd because staging and production both point to the same certificate.
I had similar error in my project
Error: certificate has expired
at TLSSocket.<anonymous> (_tls_wrap.js:1116:38)
at emitNone (events.js:106:13)
at TLSSocket.emit (events.js:208:7)
at TLSSocket._finishInit (_tls_wrap.js:643:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:473:38)
at TLSSocket.<anonymous> (_tls_wrap.js:1116:38)
at emitNone (events.js:106:13)
at TLSSocket.emit (events.js:208:7)
at TLSSocket._finishInit (_tls_wrap.js:643:8)
at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:473:38)
it turned out that the problem was in the external service that was used for tracking user events (Amplitude). Their Sectigo's legacy AddTrust External CA Root certificate had expired which impacted many companies across the internet. To resolve that issue they had upgraded their package with the new endpoint and a new certificate.
So if someone encounters similar issue, first think of all possible external services that are used within the app.
I had the same problem, for me a remote "playground" server got expired certificate. (a server to which node was trying to connect through a web-socket)

Twitter Stream & Node js server Error

I am trying to connect connect to twitter streaming api and I am getting the error
events.js:87
throw er; // Unhandled 'error' event
^
Error: Bad Twitter streaming request: 401
at ClientRequest.<anonymous> (/home/vikas/t4d/node_modules/twit/lib/oarequest.js:202:19)
at ClientRequest.g (events.js:201:16)
at ClientRequest.emit (events.js:109:17)
at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:421:21)
at HTTPParser.parserOnHeadersComplete (_http_common.js:113:23)
at TLSSocket.socketOnData (_http_client.js:312:20)
at TLSSocket.emit (events.js:109:17)
at readableAddChunk (_stream_readable.js:164:16)
at TLSSocket.Readable.push (_stream_readable.js:128:10)
at TCP.onread (net.js:540:20)
THe official api says it as Unauthorized access, but I am sure I have the right credentials (I have tested them before).
Also my www file has the entry
nconf.defaults({
'PORT': process.env.OPENSHIFT_NODEJS_PORT || process.env.PORT || 3000,
'BIND_IP': process.env.OPENSHIFT_NODEJS_IP || '127.0.0.1'
});
where putting 127.0.0.1 is also fine. I don't understand why I am getting the error and how to remove it ?
I am using the code for connecting from here. I have all the dependencies installed.
Thanks a lot for your help.
I patched this with updating the system time, it was delayed with 5 minutes. Since the date time is OK, the request is successful.

Resources