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
1answer
99 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 ...
1
vote
0answers
13 views
Optimizing redis cache
I am new to Express so I'd like to clear my code. This is Express with Redis support. I am getting someId and then I am searching it on Redis or using scraper which ...
2
votes
0answers
19 views
Using bind instead of promises or stacked callbacks
I've seen tutorials about node promises and such but not using bind. I feel like I can do lots of things this way and keep everything clean:
...
4
votes
1answer
45 views
Saving away URL query parameters in an analytics application
We are trying to use NodeJS for analytics. The following code gets the parameter from a URL and dumps it into a flat file. Is there any way to optimize it to get better response time?
...
2
votes
1answer
14 views
Saving and loading parts of configuration
I have a piece of code where I have string pairs (eg. 'a' and 'AA'), where both have their own unique ids. Id for first object is configured by user and second id is received at some point during ...
2
votes
0answers
15 views
Optimizing D3 Stream Graph Code
I have two javascript functions that generate a D3 Stream graph. I feel I may be excessively and unnecessarily iterating over my dataset to get it into the desired form.
How might I optimize or ...
7
votes
1answer
768 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 ...
4
votes
1answer
100 views
NodeJS logging module
This code is for a NodeJS logging module. I created it because I wanted to find a way to log different type of things but not show them all at the same time. I also wanted to format the logs in a ...
1
vote
0answers
15 views
Pulling data quickly from mongodb with node.js
I am currently struggling with a request I am making to my server that is taking more than 4 seconds!
I am using socket.io, express and mongoDB in the back end.
I cut out a lot of the cruft to ...
0
votes
1answer
17 views
Node.js RethinkDB connection wrapper with built in retries
I wrote connection logic for a wrapper around RethinkDB in node.js. While it works, I know it can be cleaned up, and done in a better manner. Essentially the logic is start at the first host in ...
2
votes
1answer
63 views
Parameterized route
Is this approach considered good practice, or should I create separate router.delete functions for all my routes? Please, explain why.
...
3
votes
1answer
735 views
Memory leak in a scraper
This is a scraper written in CoffeeScript 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 ...
0
votes
1answer
65 views
Testing console.log output using assert.deepEqual in NodeJS
I'm new to testing and NodeJS and I'd like to test the output in console.log using assert.deepEqual to test whether or not the result has correct data.
For ...
1
vote
1answer
150 views
Node.js Paging with Mongodb
I want to create variable paging on Node.js with MongoDB. I use MongoJS on client side create a request:
...
2
votes
0answers
40 views
Mocking the file system within a test
I've been using this method to test file-system functions as an alternative to mock-fs due to its lack of symlink support. I'd love to hear what others think and ...
10
votes
2answers
618 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
47 views
Toggle logical NOT operator based on a boolean value
I'm trying to think of a better way to write the below Javascript/NodeJS code without having to check the value of the boolean using an if statement. I know this ...
5
votes
1answer
141 views
JavaScript 8-bit floating point
To start, I am in the wrong language and I think it is time learn some C++ and compile it as an add-on for NodeJS. For now, though, I have a few code snippets that work that may be interesting or may ...
0
votes
1answer
46 views
How to achieve or ensure efficient and RAM kind Node.js code?
I'm sharing this REST API controller code in order to make it work better, also, to become a better developer. I'm having this issues with the application that API handles and I also need to improve ...
2
votes
0answers
24 views
Modify records at one time
Do you think this works well? I.e, do I need to close the database connection at the end? The goal is to be able to upsert and delete many records in one shoot.
Here is is an example HTTP POST ...
0
votes
1answer
27 views
File existence promise
I hate to have to write a custom exists promise every time I need to know if a file exists, so I came up with this. Thoughts?
...
2
votes
1answer
45 views
Function to check that two objects have “equivalent” values
I have two objects, a bet and a match. A match has 2 teams and both teams get a score at the end of the match. A bet has two scores set up before the match begins. Here I need to know if the bet ...
0
votes
0answers
12 views
Chain-able promise file system functions
I'm trying to invent an easier way of working with the file system. Here I chain promise methods together.
...
3
votes
1answer
36 views
Mapping file data to environment variables
This is a follow-on to my previous question: Enforcing set environment variables
While learning more about JavaScript, node, and the bluemix environment, I have been using the loading of process ...
7
votes
2answers
145 views
Enforcing set environment variables
Context
I have a node.js application that uses many other modules and libraries. Some of these modules pull details from process environment variables, such as URL's for databases, credentials, and ...
5
votes
0answers
52 views
Processing files with streams
I'm using iojs. I have to read some files as a stream, process them with a same function and join them back into a stream. So, I decided to create my own solution with ...
3
votes
1answer
36 views
Updating an incoming PUT query
I have the following spaghetti update method and I would like to improve its coding style.
This takes an incoming PUT query for a survey object and updates it accordingly.
...
3
votes
1answer
74 views
sed-like attempt from database
The following code and test data works, but I have had to add delays between writes to MySQL otherwise it acts funny (especially on the target data set which is over 700 rows). The table is simply a ...
4
votes
1answer
51 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 ...
0
votes
1answer
57 views
Running async processes in node.js on multiple cores
Using the async and child_process modules, I can create true asynchronous processing. My question is, how can I ensure that it ...
1
vote
2answers
103 views
Parsing sentences to create a chat bot
I am developing a chat bot with Node.Js. I am trying to find efficient way to parsing sentence.
...
3
votes
1answer
67 views
Realtime chat service
I am new to Node.js and Socket.io. I implemented a realtime chat service that has a chatroom feature. When the actual product is launched, there will be at least 200 concurrent users with 50 groups of ...
5
votes
1answer
324 views
Minimax for Tic-Tac-Toe
I have written AI for Tic-Tac-Toe using Negamax in JavaScript. The Negamax object is translated from an implementation written in Python. The code runs on a Node.js server and the player interacts ...
4
votes
1answer
78 views
Tic-Tac-Toe command line
I created a simple Tic-Tac-Toe. I'm looking for any critiques from a code standpoint: general structure / style / efficiency.
Unfortunately I couldn't get a live demo working because of the ...
2
votes
1answer
91 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 ...
1
vote
1answer
57 views
Node.js Electrolyte constructor [closed]
The code below works, and I'm not that unhappy with it, it just feels a bit awkward. Is there a cleaner way to setup an electrolyte component with multiple methods on the object? The examples don't ...
4
votes
1answer
54 views
Event driven timed I/O
The following code is used to access a shield which converts settings written over I2C to Servo output.
I make use of the MRAA library since that's the default supported by my hardware.
To prevent ...
4
votes
1answer
84 views
Using EJS for a web page
For a few reasons I had to use EJS on a specific page in my Express project. This was previously like 13 lines of code with MustacheJS and a small JSON file. But now that it is hard-coded, it is a ...
1
vote
0answers
103 views
NodeJS authentication function rewrite with promises
I will post both of the modules, some of the code in them may be "irrelevant" for the main concern here, which is Security.prototype.authenticate(). Nevertheless, comments are welcome about all of the ...
0
votes
1answer
39 views
Separate logic in files node
I have a Node project and am trying to make my code better, so I've created a new folder with a file like following which encapsulates the read and write file.
This is working and my question is if ...
2
votes
0answers
39 views
NodeJS ReadableStream _read implementation, ArticleReader with changing dates
I have a NodeJS stream.Readable, ArticleReader. Its job is to read articles, Meantime I have to give it a date to signify the ...
4
votes
1answer
182 views
User-like MongoDB implementation
This is my first implementation of MongoDB, much much more to come. This sheds light on some things like how I've structured my collection. I hope to gain feedback and insight from the community on ...
1
vote
0answers
31 views
Structuring my 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 ...
0
votes
0answers
102 views
Secure and optimize Mongoose model component
Please help in deciding if this method for a Mongoose model component for user authentication can be made more secure and optimized, for efficiency and platform independence.
...
1
vote
1answer
72 views
DNS lookup function
How can I combine multiple DNS lookups without nesting a whole bunch of if else statements? How would this impact performance? I ...
2
votes
1answer
58 views
Net health monitoring
This is a little net health monitoring project I made in NodeJS. It pings google every second and stores the result (true/false) along with the date in a database (MongoDB).
I've collected enough ...
2
votes
1answer
38 views
Dependency Injection with classes which are created often
I have a question about dependency injection and best practices when using simple classes which are meant to be created often, which have dependencies on external services. Here's a (vastly) ...
3
votes
2answers
136 views
Generate URLs from a complex JSON object using recursion
My task is here as follows :
Input : A complex/nested JSON object with nested arrays as well
objects
Output : A JSON object that contains a set of URLs with their titles:
( key,value ) ...
2
votes
1answer
40 views
Node.JS Twitter Count Module
I would like someone review this code and tell if it can be done better, or if the code is elegant and simple enough for the task at hand.
I used code climate and I got 4/4 and my test coverage is ...
4
votes
0answers
130 views
RSS parser for Node.JS
I would like someone review this code and tell if it can be done better, or if the code is elegant and simple enough for the task at hand.
I used code climate and I got 4/4 and my test coverage is ...