Skip to main content

Questions tagged [express.js]

Express is a minimal and flexible Node.js web application framework, providing a robust set of features (regex-based routing, sessions, multiple view / templating engines) for building single and multi-page, and hybrid web applications.

Filter by
Sorted by
Tagged with
1 vote
0 answers
73 views

To-do app with TypeScript backend (violations of TS best practices or unidiomatic code)

The working code in full is here. It's a To-Do App with a TypeScript backend, written as practice for an upcoming 4-hour interview for a TypeScript backend role. My colleague and I would like to know, ...
Andrew Cheong's user avatar
0 votes
0 answers
46 views

Express Auth - Session middleware to check the user is authenticated

I am building an API with Express and NodeJS. I have made this middleware to check before executing my controller, that the user is logged in. It has taken me quite a while and I would like if another ...
Enrique Moreno Tent's user avatar
2 votes
1 answer
100 views

Consuming sharded database using node.js

I think the only big improvement that can be made is to check which shard to query based on the userIds of the followed users. One easy way is to check the last ...
Sayaman's user avatar
  • 415
0 votes
1 answer
26 views

MVC Pattern - Need to include services file or not?

I am refactoring an old project, made in Nodejs with Express, applying the MVC pattern, today it is a fairly simple project: handling of the FCM and Remote Config tools from Firebase. Would it be ...
JRR's user avatar
  • 57
2 votes
1 answer
74 views

Session-based authentication using Express.js

I'm currently learning Express.js and I wrote this authentication code. I'm unsure if what i have is correct, how to improve it and if it's secure. For user and session data storage I'm using ...
Krneki123's user avatar
0 votes
0 answers
39 views

Write Node.js code to receive HTTP calls that initialize and update objects stored in JSON files

This is a backend side of Node.js running a simple Http endpoints for a monitring system for a time-related task I recently developed a habit that I would rather spend time to make the code as less as ...
Chase's user avatar
  • 191
1 vote
0 answers
50 views

Weather and health app

This is a weather app that provide health and weather details based on the location you enter. Can someone help me to review my code? ...
Salvius Fernandes's user avatar
1 vote
1 answer
130 views

Rock, paper, scissors game in expressjs typescript

This is a simple 2 player game made in NodeJS and the ExpressJS framework with typescript. I've built using OOP approach to as far of an extent as I know of it. I'm really curious as to how further ...
Exodus Reed's user avatar
4 votes
1 answer
75 views

Basic node authentication system

I built a basic authentication system for a node application and I have some security concerns. The username and password the user enters when they log in are stored as plaintext using express-...
HDawG's user avatar
  • 43
1 vote
0 answers
214 views

Promise in an Express app to send OTP verification e-mail

In this code I'm using nodemailer for sending otp email from my gmail account. I have also used ejs for creating html templates for emails. This code works perfectly, but I am a bit concerned about ...
Bhaskar's user avatar
  • 133
1 vote
0 answers
41 views

Is my e-commerce app's code compliant with MVC?

Hi I have spent few days reading about various architectures and decided to use MVC (Model-View-Controller). But I had hard time applying all the theory to my node.js code. I've wrote some minimal ...
Faig's user avatar
  • 11
2 votes
1 answer
152 views

Express.js and jsonplaceholder application

I have put together a small node application with Express.js and jsonplaceholder. On the homepage, it displays posts by all users. You can also filter posts by one user (author). In ...
Razvan Zamfir's user avatar
3 votes
0 answers
72 views

Simple Markdown Blog

this is my first real website I created after learning about web development. It's amazing to me that anyone would spare their free time to code review strangers' code. So thank you in advance. I'd ...
Paulemeister's user avatar
1 vote
1 answer
77 views

Is this good practice to declare variables freely inside async function?

example: ...
Sha'an's user avatar
  • 125
1 vote
1 answer
805 views

Common CRUD function in node js using Express

I have created common function for CRUD operations. I am using Sequelize JS, I have created all models in Sequelize I have written stored procedures in mysql for CRUD operations for each module/...
Prasad Gavande's user avatar
2 votes
2 answers
70 views

Blog API implementation in node.js

This code is from my blog project. This project is almost done. This is working well. I can create new posts and update and display all saved posts. ...
Bhaskar's user avatar
  • 133
1 vote
1 answer
74 views

Making my login function more readable and maintainable

I recently wrote a login function in my express application that does the following: Verifies the user's email and password are correct Generates a JWT Access Token with a short expiry date, and then ...
Tony's user avatar
  • 13
3 votes
0 answers
55 views

Right structure, three-layered architecture webdevelopment

My question is have i gotten the three-layered architecture right with error handling etc. I have a webpage containing different resources. The code works but I am not sure if have structured it ...
PreKaGit's user avatar
2 votes
0 answers
44 views

Tiny REST API for making CRUD operations on list of posts

This is not a question related to a bug.I've just created a very tiny node.js/express API for education purposes. I've created a very little ...
Christian LSANGOLA's user avatar
4 votes
1 answer
154 views

Catching Errors in Factory Method with express.js

My express.js application uses a lot of promises for interacting with a variety of services. Instead of including try/catch with each one, I've setup a fail safe factory method for all my express ...
Josh's user avatar
  • 143
1 vote
0 answers
302 views

Creating a transaction with node-pg and Express

I'm trying to write a TRANSACTION with node-postgres in an Express API. [The code below works as it's supposed to, mostly ...
user7496931's user avatar
7 votes
2 answers
1k views

Take postcodes and get the Lat long information from them

I had an interview task which was the final stage, however, the feedback I got back for my solution was that it lacked effort and structure. I would be grateful to ...
user6248190's user avatar
5 votes
1 answer
185 views

Express.js blogging application

I have put together a blogging application with Express, EJS and MongoDB. There is a public, front-end part and a dashboard. In index.js I have: ...
Razvan Zamfir's user avatar
6 votes
1 answer
637 views

Any better pagination logic?

router/article.js ...
viviet's user avatar
  • 63
1 vote
1 answer
153 views

Basic REST API for manipularing a MongoDB collection, using Node, Express, and Mongoose

I'm practicing back-end programming and NodeJS. As an exercise, I'm attempting to build a REST API for a MongoDB collection. I'm also learning to use the Express and Mongoose middle-wares, so that's ...
NPN328's user avatar
  • 761
2 votes
0 answers
71 views

Express compatible JSON Web Token authentication middleware

I am writing an Express.js middleware function in a TypeScript NodeJS project that uses a function from a third-party module to perform a small workload. When writing unit tests, I want to mock this ...
Patrick's user avatar
  • 263
2 votes
1 answer
86 views

Role based permissions in Express.js

This is something I've done a few times, but I've found it to feel a bit error-prone with so many conditions, and am wondering if anyone can point me in the direction of a cleaner way. This is a PATCH ...
Aurast's user avatar
  • 121
2 votes
1 answer
283 views

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

To learn the ropes of Node.js and Express, I'm trying to implement a very simple REST API. The API says what it should do instead of doing it, so I can focus on the framework's structure. The ...
NPN328's user avatar
  • 761
1 vote
0 answers
1k views

What's the proper way to do MongoDB aggregation query with optional parameters?

I have this api endpoint where i want to lookup a user or multiple users schedule and also specify the month or/and the day when doing the query. My code works, but i feel like there is a better, ...
Adrian Sultu's user avatar
7 votes
1 answer
344 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. ...
Adrian Sultu's user avatar
1 vote
0 answers
80 views

Typescript Express - Controller in Controller via dependency Injection or logic in routes

I'm trying to give one Controller one operation. However, some Controllers exists of 2 or more operations. I'm not sure whats the best way to structure this part of the app. For example, I have 2 ...
Dusty48's user avatar
  • 111
1 vote
0 answers
108 views

How to refactor below nodejs code to unblock event-loop?

I produced below code and soon it became outdated due to the blocking nature of it's loops which I can't see how to avoid that. Work-flow summery Client send a request to "/" to get a list of JS ...
inckka's user avatar
  • 119
2 votes
1 answer
112 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. ...
jecorrales's user avatar
3 votes
0 answers
410 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 ...
ubuntu7788's user avatar
3 votes
1 answer
109 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 ...
Felix Wieland's user avatar
0 votes
1 answer
240 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 ...
Dewald Els's user avatar
0 votes
1 answer
59 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 ...
ubuntu7788's user avatar
1 vote
1 answer
31 views

Express error if agency not found middleware

In an api I'm building, I have multiple routes that require an agency to exist before any action is performed on the requested agency. To avoid repetition I've written some middleware to check that ...
mrmadhat's user avatar
  • 148
1 vote
1 answer
81 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 ...
mohamed adel's user avatar
2 votes
1 answer
52 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 ...
Jojo Bagings's user avatar
2 votes
0 answers
43 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 ...
Naveen Chand's user avatar
4 votes
2 answers
60 views

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

Background A request (req in the code) is made to my server, and a response (res) returned. By the time the response has ...
Tom Hosker's user avatar
1 vote
1 answer
38 views

Express server for an artists website

I am currently creating a website for an artist (my grandfather). My main concern with the code below is readability, as for the most part I have not worked with others on a (programming) project. I ...
MilesZew's user avatar
  • 167
3 votes
1 answer
480 views

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

We have an upcoming project at work which is going to require working with express.js. I have no prior experience with node.js, so I thought I'd try and do something aside from some courses. Are there ...
Reez0's user avatar
  • 143
2 votes
0 answers
108 views

Writing error handling and users routing for my JSON RESTful API

I'm currently making an app for my side project and I was looking to get some insight on the main js file, what can I improve, the error handling, what am I doing wrong, etc. I'm mostly confused about ...
Anthony's user avatar
  • 21
2 votes
1 answer
474 views

Blocking requests within Express

Is this the correct way to block requests in Express? app.js ...
shorif2000's user avatar
2 votes
1 answer
59 views

Middlewares with Route definition or Routes with Middleware definition

I am currently working on an Node based Express application. I have found Express's middlewares approach quite pleasing however, we all run in scenarios where a certain route or routes don't need a ...
Muhammad Talha Akbar's user avatar
4 votes
2 answers
282 views

An Express route, which renders a page, and makes use of socket.io

This is the code for a basic endpoint in my express app routes folder. This firstly renders a page, and then on a continuous loop, renders information about some random "Breaking Bad" character. The ...
Dan Savage's user avatar
3 votes
2 answers
155 views

Reading image files asynchronously and displaying them on the page

I am trying to display images from a folder in my project using the "fs" module with NodeJS. I need to read all images in a directory and run them in a loop for them to be displayed. I was able to do ...
Vhin Gabuat's user avatar
2 votes
0 answers
27 views

Error handling in express without middlewares and using class structure

This is a simple implementation of Django's sample project "Poll" using and express. The controller code: ...
E.ss's user avatar
  • 21