Twitter Stream & Node js server Error - node.js

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.

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.

error: database "dbName" does not exist Node.js PostgreSQL

I'm just starting with Node.js and I'm following this tutorial https://dev.to/glaucia86/developing-a-crud-node-js-application-with-postgresql-4c9o
when setting .env file as suggested
DATABASE_URL=postgres://{db_username}:{db_password}#{host}:{port}/{db_name}
so
DATABASE_URL=postgres://vinnytwice:pass#localhost:5432/fixit
I start the server with npm start command when using Postman to send a Post request I get they error in console:
vinnytwice#Vinnys-iMac fixit_server_node % npm start
> fixit_server_node#1.0.0 start
> node server.js
App executing to port 3000
error: database "vinnytwice" does not exist
at Parser.parseErrorMessage (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket.<anonymous> (/Volumes/ProjectsSSD/FixitServer/fixit_server_node/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:369:20)
at addChunk (node:internal/streams/readable:313:12)
at readableAddChunk (node:internal/streams/readable:288:9)
at Socket.Readable.push (node:internal/streams/readable:227:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
What am I doing wrong ?
Many thanks.
Finally found the problem, the .env file wasn't at the root of the project.

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

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.

Node.js http server crashes with unknown IP address displayed

I am running a Node.js HTTP server, and suddenly the following message is displayed, and the server crashes:
UPDATED ERROR LOG: (after edit)
Uncaught exception in main server
{ Error: connect ETIMEDOUT 139.99.8.126:80
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
code: 'ETIMEDOUT',
errno: 'ETIMEDOUT',
syscall: 'connect',
address: '139.99.8.126',
port: 80 }
Uncaught exception in main server
{ Error: socket hang up
at createHangUpError (_http_client.js:253:15)
at Socket.socketCloseListener (_http_client.js:285:23)
at emitOne (events.js:101:20)
at Socket.emit (events.js:188:7)
at TCP._handle.close [as _onclose] (net.js:497:12) code: 'ECONNRESET' }
This is a foreign IP address not used by us.
I tried to grep into all node modules for this IP address and see nothing.
Appears to be a hacking attempt but I have no clue where to start looking.
Any help will be appreciated. I have blocked the IP address in the firewall.
As per node.js docs about errors say:
ETIMEDOUT (Operation timed out): A connect or send request failed because the connected party did not properly respond after a period of time. Usually encountered by http or net — often a sign that a socket.end() was not properly called.
You should create a handler for errors, so your server won't crash:
netSv.on('error', function (error) {
if( error.message.code === 'ETIMEDOUT' ){
// mail the error with some additional data to you or do something with it
}
})

How to fix RequestError: Error: connect ETIMEDOUT while running Mocha JS/NodeJS test from behind proxy

I am getting the below error while trying to run Mocha JS test case which runs npm request-promise to call a REST service. I was able to connect to the REST URI endpoint through ARC client bur it failed with below error while running through organization's proxy-
RequestError: Error: connect ETIMEDOUT SERVER_IP:SERVER_PORT
at new RequestError (<Some_Path>\errors.js:14:15)
at Request.plumbing.callback (<Some_Path>\plumbing.js:87:29)
at Request.RP$callback [as _callback] (<Some_Path>\plumbing.js:46:31)
at self.callback (<Some_Path>\request.js:188:22)
at Request.onRequestError (<Some_Path>\request\request.js:884:8)
at TLSSocket.socketErrorListener (_http_client.js:309:9)
at emitErrorNT (net.js:1277:8)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
I fixed this issue with adding the following in the request-promise options-
proxy:'http://PROXY_SERVER_IP:PORT#'
I hope this helps.
Cheers,
Kunal
This worked for me
var request = require('request-promise').defaults({
proxy:'http://username:password#host:port',
strictSSL :false
});

Resources