All Questions
18 questions
6
votes
1
answer
1k
views
Implementation of exponential backoff algorithm
You can read about the algorithm here.
An exponential backoff algorithm retries requests exponentially, increasing the waiting time between retries up to a maximum backoff time. An example is:
Make ...
5
votes
1
answer
6k
views
Node.js callback error pattern
The errors are passed through every callback, but in fact, it might be better to throw an error at higher levels. For example, look at the mongodb.js database function. It passes through an error in ...
4
votes
2
answers
108
views
Writing a user's profile image to disk using nested Node.JS closures
I am writing non-blocking code as it should be in Node.JS. If I want run function A after B I do it using callback.
But I find this style guide:
Use closures, but don't nest them. Otherwise your ...
4
votes
1
answer
1k
views
Loading a database table using a promise chain
I am creating a util module that I'm using to communicate with a MS-SQL database. I want each public method to return a promise. I started with a private function that executes a DB query and returns ...
4
votes
2
answers
180
views
Querying MongoDB for information on a collection of books
I have this huge chunk of code. Is there any better to write this code, or am I too paranoid that I check every MongoDB query for error?
The logic is here:
...
4
votes
1
answer
1k
views
If vs try/catch
The following code, written in synchronous Node.js and intended to be used as a shell script, nests a try/catch inside a conditional.
Because both the conditional and the try/catch serve a similar ...
4
votes
1
answer
1k
views
Node.js http retry do while mechanism
I have implemented a simple do/while loop to handle a http request to a third-party. I don’t know when the data I receive will have elements in its array so I retry up to 10 times until the array ...
4
votes
1
answer
81
views
Continuable if error is null
I made a method that I can use to avoid having to handle errors from callbacks.
What it does is, call the passed method only if the first argument is null.
So essentially it will bypass to the last ...
3
votes
1
answer
8k
views
Mongoose promise & error handling
I search for rails-like way of writing NodeJS code and it's more then hard to find the right way. The code quickly become bloated and unreadable. I would like my code to be as clean as possible.
...
3
votes
1
answer
263
views
Seeding a file with fake records - doing concurrent updates
I need to seed a database with user data.
When trying to write records to a file using sqlite3 with node, I tried writing the logic in a naive manner, without any error checks - but it was failing ...
3
votes
0
answers
261
views
Keeping error details out of responses (Restify)
I'd like to make sure error details are never sent out in responses from my restify-powered API. The best way to achieve that seemed to be via wrapping server.formatters in another function which ...
3
votes
0
answers
157
views
Sourcemap translator service
This is my first attempt to a serious Node.js application, I've tried to follow the async style of Node at my best, but I have several doubts and I am sure that this code can be massively improved.
...
2
votes
1
answer
177
views
Command handlers in node.js
Description
This javascript code uses tmi.js to listen for chat messages in a Twitch chat and perform certain actions depending on their content. In the sample code ...
2
votes
0
answers
297
views
JavaScript proxy for better stack traces from external libraries
I've been using the excellent pg-promise library for a few years now, but my primary irk with it is that the stack traces are sometimes unhelpful. For example, the following test will fail (currently ...
1
vote
2
answers
113
views
Error handling for a simple 'fetch some data, then save the data' Node function
This is a fairly simple bit of code:
...