15
votes
3answers
1k views

Converting an IP

I've written a DNS tool in Node and would like to know if there's a better and more efficient way of handling the conversion from an IP to a long. I'm not too good at bitwise just yet and would like ...
15
votes
0answers
1k views

How can this simple handler in NodeJS be improved? [closed]

I have a pretty simple script which I am running in NodeJS (v0.6.5) to handle requests for two different host names. The script sends back a different response based on the hostname of the request, ...
9
votes
1answer
196 views

node.js passport wrapper

I have started some experiments with node.js. Any comment on style (especially the callbacks) and best practice is appreciated: PassportControl.js ...
8
votes
1answer
86 views

Download a file and update the current downloaded percentage

I am not a big fan of JS, but have been forced to use it in this situation for various reasons. My task: Download a URL to a target file, and update another part of the application with the current ...
8
votes
1answer
223 views

node.js Passport Wrapper 2

First attempt was done here: My second attempt (now using jslint to make sure the spacing is correct and have incorporate the majority of the feedback from previous attempt). ...
7
votes
2answers
94 views

Handling packets in nodejs for MMORPG

Writing a MMORPG server in nodejs, I have to handle packets. These packets have a structure of <length> <id> <data> So what I did was use a ...
7
votes
2answers
143 views

Local user registration

More javascript (nodejs) to go with the passport wrapper I just posted: UserBook.js ...
7
votes
2answers
167 views

Nodejs broker between mongodb and rabbitmq

I wrote a small program that aims to take some data from the mongodb database and put them in the rabbitmq queue. I tried to use only promise style but I am a beginner in javascript. Could you please ...
7
votes
1answer
252 views

node.js + Express code critique

I'm learning Node. I'm working on a personal project that uses Node + Express + Node-MySQL + Generic-Pool (for MySQL pooling). I am new to the idea of module.exports and I'm still grokking it. The ...
7
votes
1answer
902 views

Nested template variable access in Meteor

I'm a brand new JavaScript guy (currently playing with Meteor) and would love some critique of the following: The goal: I've got two collections Buckets Widgets. I'm displaying a ...
6
votes
2answers
77 views

Is this the right way to work with callbacks and the EventEmitter?

I'm creating a small online multiplayer game in NodeJS and I'm wondering if I'm "doing it right". Here is a bit of my code: ...
6
votes
3answers
224 views

Avoiding callback hell

Currently, the code below looks awful because of all the callbacks involved. How can I reduce the amount of nesting? Also, would you recommend the use of q or Async.js? ...
6
votes
1answer
129 views
5
votes
1answer
2k views

Node.js callback error pattern

controllers/users.js ...
5
votes
1answer
59 views

Project Euler #41 - pandigital prime

I've written a solution to Euler 41: We shall say that an n-digit number is pandigital if it makes use of all the digits 1 to n exactly once. For example, 2143 is a 4-digit pandigital and is ...
5
votes
2answers
111 views

A more efficient approach to existing JavaScript coding

I am now working on a Node.js project, and on my ejs view page, I'm retrieving this array of objects, like: ...
5
votes
1answer
602 views

Seeding MongoDB using Mongoose models

I'm using mongoose to seed a mongodb database based on my mongoose models. I'm particular interested in improving the seed code. I have two models, an article and a category. The relationship between ...
5
votes
1answer
196 views

Express.js controller with Node.js style exports.methods

I have some Node/Express.js controllers which implement the exports.method Node module convention. This particular controller also has a few helper methods. The code works fine! However, I'm a ...
5
votes
1answer
826 views

Test mongoose model

I have mongoose model: ...
5
votes
1answer
364 views

Movable Square-Div with Web Sockets, ws module, Node.js, and jQueryUI [closed]

I'm trying to make a simple little program in Node to use as a code base from with to program my whole web app. However, it isn't exactly working as planned because I'm stuck. I wanted it so that ...
4
votes
3answers
48 views

Building SQL from multiple combinations of query parameters

I have a node.js/express.js based REST application. In one GET service I am querying data based on different set of request parameters. I am looking for a better way to implement it. ...
4
votes
1answer
69 views

Reducing code duplication in a geometric function

Given a large bounding rectangle ("envelope"), a list of points, and a maximal aspect ratio, the goal is to find a rectangle within the envelope, whose aspect ratio is bounded within the given aspect ...
4
votes
1answer
103 views

How to refactor common methods that depend on local variables into a base class

I'm using Node.js and am creating some models for my different objects. This is a simplified version of what they look like at the moment. ...
4
votes
1answer
189 views

Modularize this node.js express server code for routes and session handlers?

I have express node.js server code using Passport. It receives a user to authenticate it and ...
4
votes
1answer
242 views

Node.js chat client

This is a chat using Node.js, socket.io and MongoDB for storage. I'd appreciate any feedback on what can be improved. I understand that this allows for non-unique usernames to be used, and it's ...
4
votes
1answer
1k views

User management in Node.js

I have moved all my web-server code dealing with user management into a single Node.js module that I pasted below. I have spent time polishing it, and churned it through JSHint. I am generally happy ...
4
votes
1answer
65 views

Type / Constructor testing utilities

My argument sanitization lib has a byproduct which does some typechecking and constructor investigation. I'm unsure if I'm using the fastest / most efficient approach here. What are your opinions? ...
4
votes
1answer
4k views

How to Optimize Merge of Two Objects That Include Arrays of Objects

I need to merge two objects in a code path that is going to be heavily used. The code works, but I am concerned it is not optimized enough for speed and I am looking for any suggestions to ...
4
votes
1answer
564 views

Where is the memory leak in this scraper?

This is a scraper written in coffee-script for nodeJS. It is run in an interval (set to 5 seconds here to dramtically show the leak). Somewhere this code leaks memory. I already tried nulling a few ...
4
votes
2answers
2k views

Async, callbacks, and closures — am I doing it right?

After having spent a month or two trying to learn JavaScript, especially functional programming, async, and closures, I finally get it. But I don't know if I'm writing elegant code... Specifically, ...
4
votes
1answer
213 views

Does this nodeunit test conform to best practices?

I have inherited a node-js project, and I am completely new to it. Fortunately, it is already covered by unit tests. The class under test, FmsRescuers, has the ...
4
votes
1answer
166 views

My first implementation of mongoDB

I'm new to Code Review, my assumption is that it is a place I can get feedback on working code that I've built, I hope that is right. This is my first implementation of mongoDB, much much more to ...
4
votes
1answer
92 views

Code and concept correctness with CSV writer in node

A friend of mine wanted an array to CSV string function for node, so I came up with this, basically it can take in a single object, a 2D array or an array of objects. If the children or parent is an ...
4
votes
1answer
28 views

backbone.js boilerplate

I am currently experimenting with a backbone boilerplate application and would really appreciate some feedback or thoughts on its structure. I come from a PHP background so am used to frameworks ...
3
votes
1answer
101 views

I'm torn between conditionals and abrupt return functions

Which one of these two is better? This one: ...
3
votes
2answers
114 views

Calculate all possible combinations of an array of arrays or strings

I'm using code adapted from this Stack Overflow question to calculate all possible combinations from an array, which may contains strings. For example: ...
3
votes
1answer
54 views

Generate [min, max] range from strings

I need to generate a minimum and maximum value for a range of speeds (slow, medium, fast), the user can specify any combination of the 3 values, and receive a range that encompasses all. Given any ...
3
votes
2answers
57 views

Node exports, architecture

My project is written in node JS + Express and has the following architecture: routes (e.g controllers) models (stateless functional modules) app Models objects only doing SQL queries like this: ...
3
votes
1answer
61 views

My node app with valid syntax is failing silently, but not breaking. Infrastructure problem?

I built a simple Node app, and the code "works", with no failures, no syntax errors, and does not break, but one component doesn't work right. I showed a snippet on Stack Overflow, in this question, ...
3
votes
2answers
63 views

How deep should my nodejs closures be?

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. Right: ...
3
votes
1answer
279 views

node.js MVVM framework concept

Not sure how subjective this question is however I am looking for a peer review and general feedback on the intuitiveness and scaffolding potential of a framework concept. I have a gist on GitHub ...
3
votes
1answer
43 views

Optimize way of reading and writing file in node.js

I want to read the content of file then want to make few updates to content and then write that content to another file. I have created the code with node.js as follows. ...
3
votes
1answer
143 views

Recursively reading a directory in node.js

I made a function for recursively reading a directory and it just seems kind of long and complicated. If you could take a look and tell me what's good or bad about it, that would be great. Reading ...
3
votes
1answer
62 views

Validate that a relative path exists or is an external URI

I sent a PR to a repo the other day and want to make sure I have the right idea for URI validation. ...
3
votes
1answer
669 views

Node.js Async Callback Hell

Attempting to create a final array with data pulled from 3 functions. The first two functions have all the data but then the 3rd function needs to run looping through one of the fields from function 2 ...
3
votes
2answers
125 views

Fibonacci using cache

This is my simple Fibonacci implementation in CoffeeScript. What do you think? Using cache (fibResults), it's very very fast. ...
3
votes
1answer
357 views

Is there a better way to enforce separation of concerns in this Node.js program?

I've been writing a node.js web crawler, to get it running, I've found myself having to string together really rather a lot of different npm modules. I've done my best to keep the code DRY and well ...
3
votes
2answers
161 views

Node.js object-oriented controllers

I've been experimenting with the Express Node.js framework. On the face of it, the approach of passing functions to app.VERB methods seems unusual. In other ...
3
votes
1answer
112 views

JavaScript templating language: ivy-markup

This library is a markup parser which is intended to be used in node.js and browser environment. I've decided to use Jasmine for tests. The library's name is ivy-markup. URL: ...
3
votes
1answer
536 views

Socket.io, Express and Delivering realtime data from backend socket

I've got server running to make serial data available on a TCP/IP port. My goal is to collect data coming from a realtime device connected to the serial port and deliver it to web clients connected to ...