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.
3
votes
1answer
34 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.
...
1
vote
1answer
37 views
Can this code utilizing promises be written more succinctly?
I've written the following code to get all .txt files in a directory and read+delete them, repeating every 15 seconds.
...
3
votes
1answer
31 views
Node PSP ISO Scraper
I recently bought a PSP and wanted to know the best ISO files and wrote a scraper to retrieve games ISOs titles that received a high rating and send them to a csv. Any recommendations as to ...
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 ...
2
votes
0answers
45 views
Node.js promises: save results? [closed]
I'm new to Promises and I don't know the best practises. The following code retrieves page history then search history. I want this history to be saved in variables in order to use it later. I wrote ...
2
votes
1answer
30 views
Ensuring client IDs are unique
I'm writing a node.js application that involves handling clients based on their ID without any real way of confirming that the ID a client says it has is its actual ID. That is, it's possible for a ...
2
votes
1answer
50 views
Retaining depth information and recursive traversals
I have been using the pattern below for some time and it has worked well, but more than once I have almost bled my brain out of my ear trying to keep track of:
the recursion depth
the recursion path
...
3
votes
1answer
69 views
HTTP routing framework
I am new to JavaScript programming and would like to get your comments/input or corrections on this chunk of code. I have tried to emulate patterns from recognized GitHub projects but I still don't ...
1
vote
0answers
47 views
Cleaning if / else mess in Node.js poker game
This is the third rewrite of the poker bot I am writing. The first one was such a mess of if / elses that I could not deal with ...
0
votes
0answers
13 views
NodeJS event tracker written in LiveScript
I need to track the use of JavaScript app and wrote this:
server.ls
...
1
vote
0answers
34 views
2
votes
1answer
53 views
JavaScript Node - Private Module Functions
To learn the language of JavaScript, I did a dojo exercise by Roy Osherove. Is there a better way to organize this so that the only method exported is add while ...
3
votes
2answers
103 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:
...
2
votes
1answer
39 views
nodejs grunt plugin using async module
I'm looking for some code review of my usage of async. Mainly why this does not work without the done = this.async() method and why I don't have to invoke 'done()' ...
1
vote
1answer
106 views
Is this a reasonable way to implement promises in node.js?
I'm using passport to setup login in an express site. The site is just a playground for me to learn. The code inside login was exhibiting the arrow anti pattern so I decided it was time to learn to ...
2
votes
2answers
81 views
Using global variables in my node.js program configuration
I know using global variables in JavaScript is bad practice. Here I am using config, host and port as global variables as I have added a watch function to watch for the changes in the config.json ...
2
votes
1answer
42 views
What is the best approach to cache/memoize Promise results?
One approach it to chain cachedPromise and "regular", thus, if cachedPromise fails, we call a regular one (and caching results).
...
2
votes
2answers
178 views
Exporting routes in node.js Express 4
I'm using Express 4 to provide routes to HTML/Jade files, and as well to provide an API.
I want to separate routes from server file, and go even further- separate API from WWW. My code now looks like ...
1
vote
1answer
27 views
Testing individual nodes launched by naught using supertest
The purpose: an express node.js server which can be launched using naught, with an integration test using supertest. Each worker naught runs will test itself on a unique port, and only if passes it ...
3
votes
1answer
63 views
Socket.IO handshake module
For the server of which this is part, it makes a request to one of our web servers to validate whether the PHP Session ID is actually valid. The location ...
4
votes
1answer
173 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 ...
3
votes
1answer
42 views
Template function specialization with code duplication
I'm working on a libcurl binding for nodejs, and to get info from a curl handler, using curl_easy_getinfo, I've created a template function, the issue, is that the ...
7
votes
2answers
162 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 ...
2
votes
1answer
60 views
Looking to optimize Node.js Chat service
I've built a simple chat server/client on Node.js and socket.io that I would like reviewed. My main concern is making the chat.js (client) running as cleanly as possible (OO) and streamlining data ...
1
vote
1answer
41 views
Node.js callback closure/scope
Is it a bad idea to use the notfound callback like this? If so, why not? (bad scope/closure? I'm a noob node.js dev.)
Is it a bad idea to use the ...
1
vote
0answers
46 views
Getting the current chat room ID
I need roomId (an auto_increment primary key) to locate a specific room to update chat info. My way of doing it right now is ...
3
votes
1answer
51 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 ...
2
votes
1answer
59 views
Cleaning up nested promises in Cloud function
I am writing the Cloud function for Parse whose purpose is to update my database with a provided array of data objects. The main problem are the nested promises, which doesn't look right. Any help ...
5
votes
2answers
96 views
Optimizing simple xHTML parser
I'm writing a simple xHTML parser which parses a data without nested tags.
Example input code will look like:
...
0
votes
1answer
54 views
Promises and chained calls
I've realized JS callback hell and I started looking into Promises libraries.
After reading some articles I decided to start with BluebirdJS. I didn't realise how to properly use them yet, because ...
3
votes
1answer
139 views
node.js Passport Wrapper 3
First attempt was done here
Second attempt was done here
Huge comment at top
...
3
votes
1answer
120 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
132 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 ...
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 ...
0
votes
0answers
27 views
Properly handling NOT operators for nodejs
Converting assembly code to nodejs,
Having the assembly code:
...
7
votes
2answers
93 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 ...
1
vote
1answer
68 views
object oriented Node.js class RiddleInfo.js
So I am trying to make a Object oriented Node.js class for store information about riddles.
Please feel free to be harsh as possible. Would love to hear your ideas about how to make this class better!
...
1
vote
1answer
35 views
Remove nodejs/browser specific code in library
I'm the maintainer of the following library on github: https://github.com/edi9999/docxtemplater/blob/master/coffee/docxgen.coffee
I want to maintain a library that works on node and in the browser, ...
3
votes
0answers
229 views
Optimizing async joins for mongodb (mongoose) using async.js
I'm building a media viewer web app for a kiosk in node that uses data in mongo. To render the viewer, it gathers together all the Asset objects (representing video files), each of which belong to a ...
3
votes
2answers
51 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
60 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, ...
2
votes
1answer
75 views
Thoughts on this conversion of code from Step.js to Q promise library?
I have some code that I'd written using this pattern with Step.js. In this case, talking to MongoDB in Node:
...
3
votes
1answer
60 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.
...
1
vote
1answer
130 views
Update user's last login date
This function updates the user last login date on the user collection. I guess there are too many brackets and much spaghetti. How can I shorten this code?
...
5
votes
1answer
516 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 ...
8
votes
1answer
85 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 ...
5
votes
1answer
55 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 ...
1
vote
2answers
142 views
node.js library for extracting words from a text
I'm looking for feedback on my library for extracting words from a text: https://npmjs.org/package/uwords
The extracted word is defined as sequence of Unicode characters from Lu, Ll, Lt, Lm, Lo ...
6
votes
2answers
75 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:
...
8
votes
1answer
218 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).
...