net-36 | Encodes base to base 36 and decodes base 36 to base | DevOps library
kandi X-RAY | net-36 Summary
kandi X-RAY | net-36 Summary
Encodes base 10 to base 36 and decodes base 36 to base 10.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of net-36
net-36 Key Features
net-36 Examples and Code Snippets
Community Discussions
Trending Discussions on net-36
QUESTION
Hi there I'm doing a very simple API using NodeJS, ExpressJS and MySQLJs. I have a little form that make the request login
request to the server. The problem I have is when I'm trying to do the same request twice after the first has been finished, the server answer me with a ERR_CONNECTION_REFUSED
I was using this tutorial in order to make my code a little bit cleaner. I've changed a little because I think class makes the code cleaner than using functions
.
https://code.tutsplus.com/tutorials/managing-the-asynchronous-nature-of-nodejs--net-36183
This is the full backtrace of the error I have
...ANSWER
Answered 2018-Sep-18 at 20:20You are registering event handlers for every request. The problem is, you're not removing any of the request handlers afterwards.
For example, if you did 10 POST requests to the login endpoint, and then you do the 11th. If the 11th's is successful, the success
event is triggered for the current request but also all the other 10.
The reason you're getting Cannot set headers after they are sent to the client
is because the event listener is being triggered for a HTTP request that already completed.
The solution is to architect this different. The EventListener is not a good model for calling functions and getting results. EventListener is good for things that can trigger many times. In this case you don't want that, you only want 1 success or 1 failure per request.
The right model for this is:
A) A simple function call. It can return information related to it's success and throw an exception if it failed.
B) Return promises. Resolve them if login was successful, Reject them if not.
C) Use async/await. Again: return the result
if it was successful, throw an error if not.
D) Use the callback pattern that you're already using with express. So pass a callback with a err
and result
parameter.
The last option might be preferable because you're working with a framework that doesn't support Promises and async/await well.
QUESTION
newbie question is following:
I'm having a hard time to get the EventEmitter to work. I already considered the documentation and several best-practive tutorials like this one: https://code.tutsplus.com/tutorials/managing-the-asynchronous-nature-of-nodejs--net-36183
The problem is, that within the user.js (Class) this.emit() hits nothing. userRoutes.js doesn't trigger any user.on(), and I really don't know why..
Any suggestions are appreciated. Hints for better structuring also. My goals are centralized endpoints (well-readable) and reusing the code for every module (like user or products/orders) within different modules, e.g. calling to update an order out of the user-endpoint.
So, let's assume, you have your node.js-Server with a module configuration, router and several classes, like this:
/server.js
...ANSWER
Answered 2017-Feb-23 at 08:31It's quite simple, you forgot EventEmiter.call(this)
in function User
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install net-36
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page