Skip to main content
25 votes
Accepted

Simple NAPI wrapper around self written C++ msgpack, horrible performance

Profiling: We could use a library like Tracy to do the sort of profiling you mention in the question. But it's quicker to ask "what's taking the most time" and get an answer with a profiler ...
user673679's user avatar
  • 11.8k
13 votes
Accepted

Generate a nested structure based on a list of file paths

You can split each path at / using split and then use reduce() to build that object. <...
Nenad Vracar's user avatar
11 votes
Accepted

Printing staircase revisited

JavaScript function names should start with a lowercase character, and "staircase" is one compound word in English. Since every line is nearly the same, and only one character changes at a time, you ...
200_success's user avatar
10 votes

Checks user level and limit the data before saving it to mongoDB

According to www.lizard.ws the original's function cyclomatic complexity is 29 and for the second version is 22. Both numbers are usually considered high, and teams aim for much lower values (...
Adrian Iftode's user avatar
9 votes
Accepted

Defining an OOP structure for a Student class in NodeJS

In modern versions of node.js (v6.0 or v4.x in strict mode) or when using an ES6 transpiler, you can use the ES6 class keyword: ...
jfriend00's user avatar
  • 3,948
9 votes

Node JS routing system

It seems a little risky to me to just blindly use the language designation that the URL contains. If it's possible to trick Express into looking somewhere in your file system besides where you expect (...
jfriend00's user avatar
  • 3,948
9 votes
Accepted

Checks user level and limit the data before saving it to mongoDB

I am not a mongoDB user but is there not some type of validation API, not sure if it can be used on schemes. If it can then maybe that is the better option for your code. The Question It have been ...
Blindman67's user avatar
  • 22.2k
8 votes
Accepted

Counting newlines in a file

The two versions execute exactly the same steps, the only difference is the number of intermediary local variables. Which version is more clear can be a matter of opinion. Beginners may find your ...
janos's user avatar
  • 111k
8 votes
Accepted

Robust websocket server for use by a game running on node

A bunch of small things: In .addNewClient(), you can change this: var time = new Date().getTime(); to this: ...
jfriend00's user avatar
  • 3,948
7 votes
Accepted

Yet Another Todo API

Okay I'm going to be a bit more comprehensive here since I've already read your code quite a few times, and I'm gonna assume that you are on node v6 The setup ...
m0meni's user avatar
  • 382
7 votes
Accepted

NodeJS Promises VS async library

That bus controller is too complicated; in general you should not be using new Promise(fn) unless you are wrapping a callback, and what you're doing is better done ...
CR Drost's user avatar
  • 261
7 votes
Accepted

Mongoose: find() and count() query

Solution After reviewing many answers, I believe I have two options: Make two queries, like I am doing now, Use a pagination plugin for mongoose My decision was the second one and so I am now using ...
Flame_Phoenix's user avatar
7 votes
Accepted

Sanitation and validation of a user input 10 digits phone number

this is a client side check, if this code is ok should I check the same at the nodeJS back end? Yes! The server has no idea what's really running on the other side of the connection - all it knows is ...
Sara J's user avatar
  • 3,479
7 votes

Employee Model definition without an ORM

I cannot use an ORM because I'm required to use Stored Procedures Exchanging one for the other (and back again if you like) should not impact the Model design. So the right question is "... ...
radarbob's user avatar
  • 7,684
6 votes

Flattening multiple nested node readline questions

Also, I was looking for an answer how to flatten (and automate) calls to rl.question(). In my solution I used Promises - chained - to display questions sequentially. ...
GoldenChris's user avatar
6 votes

Printing staircase revisited

No need for the additional for loops: ...
ChatterOne's user avatar
  • 2,805
6 votes

Printing staircase revisited

This traditional Javascript code works fine: ...
Md. Jamal Uddin's user avatar
6 votes
Accepted

Sieve of Eratosthenes performance; Scala very slow compared to Node.js

Lists vs. Arrays The Scala version of your code ran surprisingly slower because you used a ListBuffer. In Scala you can think of a ...
t. fochtman's user avatar
  • 1,557
6 votes
Accepted

JavaScript function to convert an array to an array of strings (formatted)

First impressions: too much nesting, too many nested returns inconsistent style, inconsistent naming You already recognized the potential for refactoring. The simplest possible technique for ...
le_m's user avatar
  • 1,925
6 votes
Accepted

Roman to Arabic numerals converter in Javascript

You wrote way too much code. Interviewers hate wading through a lot of code. Your solution was probably rejected just based on the poor impression given by its length. The specification, which ...
200_success's user avatar
6 votes
Accepted

Node websockets

In node, throwing an error without catching it will kill the process. This seems to be the primary error handling mode (and based on this it seems you then rely on pm2 to restart the process). This ...
George's user avatar
  • 311
6 votes
Accepted

Login Server with Node.js

Just addressing one of your questions. "SECURITY: Is my website secure in any way, shape, or form?" No it is not!!! Reasons Insecure transport. You should never send private data via an ...
Blindman67's user avatar
  • 22.2k
6 votes
Accepted

NodeJS APIs folder structure

there is no right in wrong in this situation it's a question of what's best for your particular situation if you are going to build many Rest API endpoints it's best to separate them in separate files ...
Chamsddine Bouzaine's user avatar
6 votes

Calculate transaction balances and find duplicate transactions

why someone just write Overly Complex 2 times I don't know what format you originally received this information in, but it looks like there are 4 "tags" applied to your application: Overly Complex ...
Pod's user avatar
  • 233
6 votes
Accepted

Is this a good approach for creating pages for multiple content typs with GatsbyJS?

There's definitely a lot of duplicate code in those 2 ifs. I'd extract it into function and pass different things as parameters. Then code would look let's say: <...
K.H.'s user avatar
  • 2,668
6 votes
Accepted

Vowels and Consonants

From a short review; arr1 and arr2 are terrible names, we could call them consonants and <...
konijn's user avatar
  • 33.2k
6 votes
Accepted

Converting duplicate JS code into a higher order function

From a short review; Why hardcode the batch length to 500 ? Why not have the batch length be a nice constant ? You have even hard coded the length in the function name, which is really unfortunate <...
konijn's user avatar
  • 33.2k
6 votes
Accepted

Node.js backend login logic

Async login bug The try/catch around User.findOne does not accomplish anything because ...
CertainPerformance's user avatar
6 votes
Accepted

Take postcodes and get the Lat long information from them

The code could be improved with a few tweaks, but it's not bad, and the overall structure looks just fine to me. Error handling is in the wrong place Some of your route handler are ...
CertainPerformance's user avatar
6 votes
Accepted

JSON4 parser in Typescript

All in all, this is some well-written, well-structured and well-typed code. I like it! I do have a few nitpicks, though: The type of ScalarNode.type might be a bit ...
Sara J's user avatar
  • 3,479

Only top scored, non community-wiki answers of a minimum length are eligible