Node.js is an event based, asynchronous I/O framework that uses Google's V8 JavaScript engine. Node.js is commonly used for heavy client-server JavaScript applications.
4
votes
0answers
41 views
Simple Poker Game
I'm building a simple Poker game. It is almost complete, but I want to refactor it early.
To calculate hand strength / ranks, I use this library from NPM: poker-evaluator
For deck shuffling, I use ...
0
votes
0answers
13 views
Looking for a simpler way of using an asynchronous function without directly using its callback
As the title says "Looking for a simpler way of using an asynchronous function without directly using its callback.". I hate functions and re-writing callbacks by "intercepting" them and passing the ...
2
votes
0answers
37 views
Node module for DRY CRUD endpoints
As a learning project I recently started writing a node module to generate / handle the creation of CRUD endpoints in a DRY way.
The problem I was initially wanting to solve was that in my ...
4
votes
1answer
31 views
NodeJS and Express with Promises
I'm relatively new to NodeJS and Express, and I've recently run into the pyramid of Doom while doing stuff that requires multiple steps.
I've found that promises are very promising indeed. But I ...
3
votes
1answer
38 views
JavaScript traits implementation
I wanted to step up my JS game, and move on from mostly closure based scripting, so I decided to write an application in node. I don't have much experience with prototype based programming, and I ...
4
votes
1answer
43 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:
Bookcollection = collection of books
Book ...
0
votes
0answers
17 views
Validation in Node.js
I'm building a NodeJS application, but I'm not sure what will be the best way to structure my code.
I have the following model:
...
0
votes
0answers
20 views
Signature verifier for a javascript/node.js function
I wrote a function that verifies the arguments against an expected set of arguments.
test('hello', 'world');
...
3
votes
2answers
48 views
Node.js script may have memory leak
I use this node.js script to migrate MongoDB collection to a schema to another. It does work if the collection is <20k documents, but slows down to a crawl and sometime throw a
FATAL ERROR: JS ...
5
votes
1answer
43 views
Reading the contents at three URLs using Promises
I'm learning promises and now I'm trying to figure out if something in this code can be improved. This code is expected 3 urls and then async parallel calls should be done. When all requests are ...
2
votes
1answer
27 views
The best way to place callback definition [closed]
In JavaScript we can write callback definition in many different ways:
Definition after usage:
...
1
vote
0answers
11 views
NodeJS ReadableStream _read implementation, ArticleReader with changing dates
I have a NodeJS stream.Readable, ArticleReader. It's job is to read articles, Meantime I have to give it a date to signify the ...
3
votes
2answers
23 views
Function that groups rows returned from SQL DB
I have a data set returned from an SQL database contained below, as you can see all data remains the same apart from one property, "name_alt".
...
1
vote
0answers
15 views
General application log
In my Node.js applications, I often find it helpful to have an application log so that should something go wrong in production, I can have more information than I get from a crash stack trace to track ...
2
votes
1answer
26 views
Node js single mongodb connection
I want my entire node application to use one single mongodb connection, at least that's what I think is better. I wrote this little script and want some feedback on it. Especially if what I'm doing ...
1
vote
0answers
19 views
Structuring my MongoDB application documents
I'm just starting out on an application and I've heard some good things about MongoDB so I thought I'd give it a crack in this new project to see how well it works.
Please bear in mind that prior to ...
3
votes
1answer
115 views
Gulpfile.js optimization and image caching
I'm trying to write gulpfile.js, which will follow modern best practices for optimization. This project includes jekyll, SASS and some image optimization tasks. I'm pretty new to JavaScript and Gulp, ...
13
votes
1answer
140 views
Making an efficient and healthy db call for a real-time browser game
I'm doing a calculation for a real-time browser game, where users can invest some of their balances to the site. I need to update their invest's based on ...
2
votes
1answer
61 views
Node.js API route for POSTing a resource. Getting rid of callback pyramid
I'm writing an API for simple GET and POST routes. The app is a shared to-do-list. Users and lists are stored separately. A list can belong to many users, and a user can have many lists.
...
2
votes
2answers
60 views
Is my Node/Express-based authentication implementation with session properly done?
I know that Passport.js exists, however, I wanted to code my own implementation using express-session module.
I'm using:
Express
Mongoose
express-session
So I basically have 2 routes for handling ...
2
votes
1answer
63 views
ExpressJS easily serve static files
I have a NodeJS package, staticize, which takes an object of HTTP routes -> file locations, then serves them dynamically on each request.
Could I get some feedback on the latest rewrite of the main ...
1
vote
1answer
34 views
groupBy implementation in NodeJS
I came across a problem in my NodeJS app, which I solved by creating a method called groupBy. The purpose of this method is simple: take an array, and a function ...
1
vote
1answer
203 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.
...
7
votes
1answer
98 views
Node module using promises and the revealing module pattern
Can someone give me some feedback on this pattern?
I am writing a node.js module that connects to a remote API, caches JSON, returns it as output. I have a cli wrapper script that uses the module, ...
0
votes
1answer
50 views
Controller making request to an external API
I'm starting on a new node/express backend and really want to keep everything clean and well tested. My previous project got a bit out of hand (in terms of test coverage and highly coupled code). So ...
6
votes
1answer
105 views
Game Server Querying
I made a package for Node.js that allowed the querying of game servers (or any UDP server(untested)) using UDP.
What it does is sends the query to the server and adds the query into a queue. When the ...
4
votes
1answer
89 views
Bookmark application AngularJS controller complexity
I am working on a personal project for managing one's Pinboard bookmarks. Since this is already quite a big project, I am not sure if my question fits the guidelines. My main concern is with the ...
2
votes
0answers
38 views
RESTful API parsing DBF data HSET in Redis
I have this working code, but would like your review:
sync.coffe
...
2
votes
2answers
76 views
AJAX call to make an HTTP request
I am using node.js with express. There is a button that the user can click, and doing so calls this method on the server:
...
0
votes
0answers
28 views
NoSQL schema for weather data
I am using NodeJS and MongoDB for a weather app that takes the weather info from a logger, saves it to a database, and relays the data to the browser in real-time. It is hosted here with code here ...
0
votes
0answers
99 views
Push-pull pattern with nodejs and zmq
I created the code below to illustrate push-pull pattern with zmq and to benchmark some concurrent job.
...
2
votes
1answer
38 views
Move uploaded file
As I mentioned in Node.JS fs.rename can not move files in right way. And it should be solved with stream piping. Please verify this code and answer questions in comments:
...
3
votes
1answer
56 views
Optimizing a Node.io server code for self-balancing robot
I am building a 3D printed self-balancing robot, and use the attached server script to control it. I coded using node.io, express and socket.io.
The system is working, but I would appreciate some ...
2
votes
1answer
46 views
Controller code using the koa framework
I would like to gather ideas on how to refactor the JavaScript/NodeJS controller code below to be more aesthetic. The code is using the koa framework thus I use ...
1
vote
3answers
419 views
Faster way to check for a string in a array of string
I have a array of object, I need to sort them by time (hours, days or months) and separate the number of new IP.
result is an array of object with property time (JavaScript timestamp), user IP ...
2
votes
1answer
80 views
Simple web application for benchmark
There is an article where the author tries to compare performance of different web stacks. The result looks pretty controversial.
I try to prove that in real use case the difference between scores of ...
2
votes
1answer
40 views
Pyramidal promises
I have a situation in my Node (express) controller where I need to check whether a particular language has a parent language, if it does, I need to do a new DB (SQL) call to retrieve the parent ...
4
votes
1answer
239 views
RESTful API for Todos using Hapi
My goal is to create a simple restful api that will be accessed by an AngularJS front end. Even though it's fairly simple, I'd like understand how to make it more reliable, secure, and best-practices ...
6
votes
1answer
50 views
Creating a server for user Internet orders
I've been learning the basics of node over the last couple of days and finally hooked up what I needed. I'm just after someone to comment on if I have gone the right way around this task.
It creates ...
2
votes
1answer
66 views
NodeJS conditional request before the real request
In my code I have to login a user with username and password. But if the user sends his e-mail instead of his username, I have to resolve it with another request.
This is what the code looks like:
...
3
votes
1answer
70 views
Shorten my asynchronous DB queries, using async.js module
I am using
Node.js
Express.js
node-mysql.js
async.js
I am making multiple asynchronous queries to my DB, but every query relies on the previous one's results, so I decided to use the ...
1
vote
1answer
27 views
Generating Passwords with a Secure PRNG
What's the best way to approach generating a password using a secure prng? In Python, I could simply use os.urandom. Any suggestions on this?
...
4
votes
1answer
54 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 ...
3
votes
2answers
119 views
Read multiple files async
I want to read multiple files simultaneously and apply the same function on data.
This code works correctly, but can someone please suggest any better way of writing this?
...
0
votes
0answers
20 views
nodejs async to read multiple files [duplicate]
I want to read multiple files simultaneously and want to apply same function on data.
Right now, here the code which I'm using
...
2
votes
1answer
101 views
Node.js JSON searching & updating
I'm working on a web-based on/off controller for multiple switches. I'm looking for a good way to manage the current state of a switch and updating the current state on change.
So far I've got a ...
2
votes
0answers
64 views
NodeJS, status propagation to interface
If you have an interface served by a NodeJS API, what is the most clean way to propagate status changes to the interface?
For example, I have a page that has 2 statuses, user logged in and guest. How ...
1
vote
2answers
45 views
ChunkerTransformStream, a transform stream to take arbitrary chunk sizes and make them consistent
I have some code to interface with a wire protocol that requires data to be inserted into a stream at regular byte intervals. Every 8KB (or at some other definable interval), a small chunk will be ...
8
votes
1answer
163 views
Proper prototypal programming with Node.JS
Practicing Prototypal Code
I'm focusing on practicing a very prototypal structure with my code (non library oriented) to begin learning to reuse large portions of my application infrastructures where ...
0
votes
1answer
66 views
Logger module with JavaScript
I'm new to JavaScript, and in Java I probably would do this as a singleton. I need something that I can call from anywhere and instantiate only once.
This is what I have done, but I need some advice ...