12 votes
Accepted

Passing Node.js SQL connection to multiple routes

You can create a file db.js ...
Carolina Aguilar's user avatar
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
6 votes
Accepted

Using Node.js, Express, and Express Router to implement a very simple REST API

After I examine the codes you have written, I could see some things that are not rightly done. Below are the few things I highlighted: The structuring of the codebase is not okay hence it can be ...
Kater Akeren'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
5 votes

Scraping articles on a web site

As for the jQuery/function usage, there is definitely room for improvement but it would be helpful to see an example HTML element that contains the article img, <...
jmhage's user avatar
  • 86
5 votes
Accepted

Restful CRUD API with Node.js and Express

I know you are generating data for the sake of completion but it does complicate things on what aspect of the code you'd like to focus on. But here are a couple thoughts. With Express, I often like ...
Frank's user avatar
  • 316
5 votes
Accepted

Reading image files asynchronously and displaying them on the page

Don't use callbacks, it's hard to read and maintain, the fs.readdir function will return a promise if you didn't provide a callback function. Use arrow functions ...
Ehab Khaireldin's user avatar
5 votes
Accepted

Any better pagination logic?

Error handling You await inside an async function, but without a try/...
CertainPerformance's user avatar
5 votes

Take postcodes and get the Lat long information from them

Test case structure It doesn't seem like the code totally "lacked effort and structure" but the structure, at least of the test cases, could be better. Since all three ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
4 votes

Send html with nonce for each script and style tag on each request

I am unsure if this is the correct way to do this (set nonces on each get) Yes, it is Remember that nonces must be regenerated for every page request and they must be unguessable. In terms of ...
James's user avatar
  • 567
4 votes

Send html with nonce for each script and style tag on each request

Hopefully the response by James is sufficient for your concern about best practices. I did notice some redundancy in that snippet of Javascript. Specifically, the line that handles adding the nonce ...
Sᴀᴍ Onᴇᴌᴀ's user avatar
4 votes
Accepted

JavaScript / Express error handling w/ promises

There's a big problem here. getUserByEmail() can either return a promise or throw synchronously which is a bad design and very unfriendly for the caller. Instead, ...
jfriend00's user avatar
  • 3,948
4 votes
Accepted

Fetching user details, posts, and comments using promises in ExpressJS

If you use 1 promise, you would encounter a long chain of then method and all of async operations would be executed in sequence style which increases response time. If you create 3 promises, all of ...
tanapoln's user avatar
  • 156
4 votes

Express.js functions to start session, authenticate user, perform ping, search for user, reset password, and import product XML

The general rule is that you should never incorporate user-controlled input into a string that will be interpreted by a computer system without escaping it first. Specifically, at a quick glance, it'...
200_success's user avatar
4 votes

Retrieve a city list for a country and state

Utilize the query object, this type of querying is more suitable there than as params. Use object destructuring. Dry your code, see how we're mapping over ...
Ehab Khaireldin's user avatar
4 votes
Accepted

A JavaScript class, which finalises the HTML of each page of my NodeJS (Express) website

Ways of improving/optimizations: What fixApostrophes and fixDashes functions actually try to do is replacing a specific ...
RomanPerekhrest's user avatar
4 votes
Accepted

How do I refactor this fetch request?

Let me share my async await solution for that: Because Your fetch function is pretty similar till the res.text(), I would ...
Peter's user avatar
  • 199
3 votes
Accepted

Scraping articles on a web site

A good rule of thumb is to always start breaking code into smaller methods however in your case I suggest you change your logic. Instead of looping through each element updating a list of articles ...
Marc Rohloff's user avatar
  • 3,467
3 votes
Accepted

Handling login using promises

This is missing the point. It is not about promises. You are right that if done correctly, you'll get a nice flat structure, but not if you inline all your code. This would be true if you weren't ...
Magnus Jeffs Tovslid's user avatar
3 votes

NodeJS/Express/socket.io backend

A short review; Your database related functions should be separated, in my mind your socket methods should only do this: Normalize parameters your receive like with ...
konijn's user avatar
  • 33.2k
3 votes

Verifying requirements before deleting a user-parent-student-school relationship

One of the biggest things you can do to clean up you code is to simply remove the unnecessary if-else blocks. In many cases you have a return inside the first conditional, which means there is no ...
Mike Brant's user avatar
  • 9,608
3 votes
Accepted

Node.js API Server for querying a Neo4j database

It's often a good idea to separate routes into their own files to get a better overview of the project. Try out express-generator and see how the example project is organized. Use a logging framework ...
jacwah's user avatar
  • 2,661
3 votes

Custom CSRF protection in Express / Node

Not a node expert, but it looks like you cover the basics. CSRF protection via token is standard practice and very reliable. You are generating your token via a cryptographically secure random ...
Conor Mancone's user avatar
3 votes
Accepted

REST web service in Express

What you're essentially doing is transforming a list to another list (a list of <tr> to an array). Instead of jquery.each()...
Joseph's user avatar
  • 25.1k
3 votes
Accepted

POST to endpoint and GET data back

Avoid making multiple calls to express server, you can return filtered data from the POST call. Use single AJAX POST call. As your calls are being made parallel there is no way to know if the ...
Deep Vora's user avatar
  • 148
3 votes

Consume etherscan.io API, store in DB, serve from web app

I must say it a very interesting assignment to do: what I see missing from your assignment is not much bigger things in development aspects but it all have a huge impact on Code maintainability and ...
Shishir Sonekar's user avatar
3 votes

Upload .JSON product list to MongoDB and upload image to AWS S3

There's nothing outstandingly wrong, there are some minor points that can be improved. The main concern that I have is the amount of logic happening inside the ...
Quill's user avatar
  • 11.9k
3 votes
Accepted

Reading a text file, manipulating it and saving it to a mongo database

Style Comments are just noise and thus reduce readability if they state what is obvious in the code. EG the comment //Read from each line is followed by the line <...
Blindman67's user avatar
  • 21.8k
3 votes
Accepted

Basic node authentication system

Short answer: yes, don't do it. Don't put password into session. On one hand, the security of it depends on the used session store. On other hand, you don't need the password in session or anywhere ...
slepic's user avatar
  • 5,467
3 votes
Accepted

Consuming sharded database using node.js

You're using mysql.createConnection(config) inside a map function which is synchronous while ...
37307554's user avatar
  • 291

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