Questions tagged [node.js]
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.
919 questions
3
votes
1
answer
72
views
TypeScript: Object Duplication impact on performance
For a library I am working on, I have created a class WatchableCollection which will monitor an endpoint of an API for updates and issue events (...
7
votes
1
answer
400
views
How do I refactor this fetch request?
I have this code that fetches data from a 3rd party api and sends it to my backend to be processed. The 3rd party api needs to target the user's localhost address so it has to come from the front end. ...
4
votes
2
answers
415
views
How to handle multiple return statements
I am trying to restructure a function more clearly and readable that has multiple return statements.
Usecase
Get a token:
if the token does not exist in the database then generate a new one and ...
3
votes
1
answer
1k
views
NodeJS executing multiple database queries using async library
I have a use case where I need to run multiple tasks in series. Each task is required to perform some database operations. In my code step_1, ...
1
vote
1
answer
587
views
Creating a Navbar Menu from JSON data with Lodash
I am trying to create a navbar menu from JSON data. Actually I have achieved it but I am looking for feedback not to call getItems twice? How can I improve my code?
...
1
vote
0
answers
841
views
SQL transaction management in Node.js with MySQL: use the existing transaction or create a new one if none exists
I'm trying to implement a SQL transaction management in Node.js, that would append queries to an existing transaction if available, or create a new one if none exists yet, thanks to an optional
...
7
votes
1
answer
4k
views
Vowels and Consonants
From HackerRank's 10 Days of JavaScript, Day2: Loops:
Complete the vowelsAndConsonants function in the editor below. It has one parameter, a string,s, consisting of lowercase English alphabetic ...
-2
votes
1
answer
77
views
Node.js ws server: global or local functions? [closed]
I'm working on a Node.js chat app project using the ws library. I have it up and running but I'm still making improvements and adding stuff like authentication, etc....
2
votes
2
answers
96
views
String data manipulated given CSV variables
The Requirements:
List the expensable items sorted by date and location given two variables: 'categories' and 'expenses'. The Categories variable provides the following information in order: Category ...
4
votes
1
answer
5k
views
"Clean Architecture" design pattern with Node.JS and MongoDB
After some time poorly designing my web applications' backends (mixing database calls with the controller, etc.), I have decided to try the "Clean Architecture" approach.
In this example I have a ...
0
votes
1
answer
94
views
Scrape page and send user only new results
Review Wanted
Application Summary
The application is a simple screen scraper which is to notify the user when new items are posted.
The code is run as a CRON job every ten minutes. It will scrape the ...
4
votes
3
answers
246
views
Find events associated with users on a certain date in MongoDB
I have this script which works perfectly but I experienced some delays because of these 2 for loops [i][j]. Is there any way to ...
2
votes
0
answers
53
views
Mocha chai tests
I want to have a test fail, because the email already exists, so I create [email protected] and [email protected], but is there a way to do it without this?
...
4
votes
2
answers
222
views
Efficiently generate large file to create SQL table and insert sample user data
Here's a function I use to generate a 2.5 gig SQL dump file for testing. It works but it takes a long time. How can I make it more efficient?
...
2
votes
0
answers
134
views
Modeling mongoose schemas
I'm in the process of creating my first web app using node with mongodb on the backend. I could use some opinions on the schemas/models I've set up.
I have three schemas: User, Pet, Food. Here's the ...
2
votes
1
answer
1k
views
Text notifications for Facebook Marketplace posting
Application Summary
I received a call from a client asking for a "simple app" that notified him via text message whenever a "Jeep Wrangler" is posted to Facebook Marketplace. It ...
1
vote
1
answer
97
views
Node refactor if/else mess
I'd love some pointers on how to refactor this
...
4
votes
1
answer
765
views
Access token regeneration for Axios requests
Description
I've developed an application which use axios to communicate with the PayPal API. PayPal has a NodeJS SDK, but unfortunately this doesn't support the ...
2
votes
0
answers
39
views
Registering all functions that implement an interface and allowing a passed-in context to invoke the applicable function (command)
I have a Lambda function that processes incoming messages and sends emails based on an enum type property in the message. I have N number of "handlers", one per <...
2
votes
1
answer
135
views
Performance and login security for NodeJS using Express with Express-sessions
I am new to this part of backend development using JS and the truth being a new programming language (for me) it is worrying that it suddenly does not meet the structuring and / or security standards.
...
3
votes
0
answers
434
views
Mern stack app on error handling, async await, try-catch and avoiding DRY in controller functions
I'm looking for a review of my backend code on how to keep it more DRY. I see a lot of repetition in validation part of email and password, also I need some advice on if I have used the try-catch and ...
3
votes
0
answers
49
views
Decoding request object before use it in an Insert query
I want to decode a request object before use it in an insert query.
Request object containes the following JSON body:
...
3
votes
1
answer
156
views
Correct way to unit-test express API
I wrote an express API for a document management service (repo to be found here) and even though I understand the importance of unit-testing I never quite managed to wrap my head around how I would ...
0
votes
1
answer
294
views
NodeJS - Auto Module Loader
I took some time to try and solve a problem. I am building a basic Node + Express API. In the app I have created a models folder and will be adding new models as I continue development.
I attempted ...
3
votes
1
answer
1k
views
Summing CSV files row by row using Node.js events
I need to read multiple CSV files that have the same number of rows, and compute some results for each row. For simplification purposes, and in the scope of this code review, this computation would be ...
-1
votes
1
answer
507
views
JavaScript promise optional chaining [closed]
I've wrote a piece of code today that really make me sick about:
...
0
votes
1
answer
82
views
Registering a user and login
I have these following controller functions for registering a user and login, in my app, and I want to make it more clean and maintainable.
Probably by using ...
1
vote
1
answer
168
views
Python-like decorators for caching
I am building an ad-hoc text-editor. I have two functions which use a cache, provideHover and provideCompletionItems.
...
-2
votes
1
answer
124
views
Searching for a user [closed]
I'm looking for any advice on the way I have implemented methods (explained below). More specifically, is it a good practice or not? And if not, any suggestions?
NOTE - ...
3
votes
3
answers
495
views
Is this a good approach for creating pages for multiple content typs with GatsbyJS?
I'm trying to create pages for multiple content types in Gatsby and I was wondering if this is the right approach:
My gatsby-node.js file:
...
4
votes
0
answers
179
views
HSL Guessing Game in Svelte
The objective of the game is to guess the hue, saturation, and lightness values of a given color swatch across ten rounds.
https://github.com/shreyasminocha/guess-the-hsl
https://guess-the-hsl.now.sh
...
1
vote
2
answers
1k
views
Calculate transaction balances and find duplicate transactions
In an interview I was asked to solve two JavaScript questions. I thought I did pretty well because I:
Covered the edge cases
Wrote comprehensive tests
Documented the code using jsdoc
The interviewer ...
3
votes
1
answer
229
views
NodeJS CLI script to create React apps
Background
I crated a CLI tool which executes an npm command (to create a react app) and modifies the contents of the generated files. It was a practice attempt at ...
0
votes
1
answer
84
views
How to refactoring function when I've to do many things in one function
I always want to improve my code by refactoring but when I've to work with complicated function that have many thing to do . How can I refactoring them.
Here is my data for example I get data from ...
2
votes
2
answers
73
views
Asynchronous array methods chaining
I am trying to check that a list of files are all images using functional programming.
Some actions I go through are asynchronous, so I have to wait for them to completely finish before passing to a ...
4
votes
0
answers
366
views
JavaScript AVL Tree
I have been working through Introduction to Algorithms 3rd Edition, and have implemented an AVL tree through prototypal inheritance. The code presented here does work as expected based on the tests ...
0
votes
0
answers
742
views
Rust/WebAssembly VS pure JavaScript benchmark in Node.js
I've wanted to try Rust and WebAssembly for a while. I recently realized that I could try both at the same time by compiling Rust to WebAssembly.
I wanted to know what the performances of something ...
3
votes
1
answer
1k
views
Crypto createCipheriv and createDecipheriv for authentication
I'm not an expert in authentication, so I want to make sure I have done everything right.
I am using crypto.createCipheriv and ...
2
votes
0
answers
35
views
npm package as amqp client helper
I would like to build a common helper for my application that will manage all the amqplib calls from all of my nodeJS microservices.
I would like to import my amqplibHelper to every microservice and ...
5
votes
1
answer
119
views
Searching all new Reddit comments for comments matching regular expressions and notify of matches
This program constantly sends an https request to Reddit's API for new comments.
Using a PostgreSQL Database containing Regular Expressions, find comments of interest and notify about them using faye....
2
votes
1
answer
93
views
NodeJS APIs folder structure [closed]
I am going to have multiple APIs in routes folder should I put them in in the same file API or separate them?
...
1
vote
1
answer
110
views
API using NodeJS to recive data from client and send it to a server
Hello I have a NodeJS which act like an interface it connects the client(mobile app) to the actual server
My node JS API receives data from the client to verify it and send it to the server.
I want ...
2
votes
0
answers
132
views
Process data from mongodb and upload result to S3
I'm working on an AWS lambda function that take data from two mongodb databases, find the matching records between two collections by 'id' and calculate each record commission by fixed rate. Then ...
2
votes
1
answer
80
views
Express Rest API Async and Scaling
I am currently learning how to create nodejs express rest api using async making it fully scaleable and secure.
My goal is to ensure maximum functionality and speed, currently I am using MVC ...
5
votes
1
answer
93
views
Browser and Node.js compatible code require
The Reason
The reason I designed this code was that in many cases, when I wanted to test code in the browser that would be running on a Node instance, the code that I was copying (Don't worry, copying ...
3
votes
2
answers
205
views
Function to get current timestamp in node
I have this code to get the current timestamp so that I can save it as a part of the key in leveldb database.
...
2
votes
0
answers
49
views
Backend application to bookmark GitHub repository
The backend part has the following purposes.
An endpoint that takes a search term and returns a list of repositories.
An endpoint that allows bookmarking a repository by its id.
An endpoint to get all ...
2
votes
0
answers
49
views
Splitting environments: prod and dev modes
I've decided on splitting my environments keeping them in .js files in an environment folder and keep all the sensitive information in .env file (use a third-party module 'DOTENV').
That's what I've ...
5
votes
1
answer
102
views
Class for Switch statements
This is more to get clarity on an implementation that I did. I am working on a React, Node, and Electron application that essentially has a form that a user inputs values that will update some content ...
4
votes
1
answer
1k
views
discord.js/node : filter().map() best method
I'm learning javascript with discord.js and node and I'm always looking for the "best" code.
Is this the "best code" for my map() ? ([role] required, (role) optional)
...