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
0answers
56 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 ...
1
vote
0answers
31 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 ...
1
vote
1answer
60 views
1
vote
1answer
111 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/...
2
votes
2answers
54 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. ...
1
vote
1answer
63 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 ...
2
votes
0answers
44 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 ...
0
votes
0answers
28 views

Passing data between middleware in Express.js

I wrote a middleware for user authentication and I wanted to pass some data between authentication and request handler. What I thought would be a nice solution is to add that data into request body ...
2
votes
0answers
37 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 ...
4
votes
1answer
64 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 ...
1
vote
0answers
41 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 ...
7
votes
2answers
321 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 ...
5
votes
1answer
141 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: ...
6
votes
1answer
343 views

Any better pagination logic?

router/article.js ...
1
vote
1answer
142 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 ...
2
votes
0answers
58 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 ...
2
votes
1answer
51 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 ...
2
votes
1answer
83 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 ...
1
vote
0answers
265 views

TypeScript Express.js proxy server overall design and structure

I have built a Express.js proxy server using TypeScript to be able to hide my front-end API keys. I designed it to be able to include multiple API services and to reject connections that are not from ...
1
vote
0answers
568 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, ...
1
vote
0answers
31 views

Reset password implementation using JWT for easier code invalidation/expiration?

This is the first time I had to implement forget password meant for real-use so I had to cover code expiration. My questions are: Is using jwt here bad in any way other than it's not the best? If the ...
6
votes
1answer
181 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. ...
1
vote
0answers
34 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 ...
1
vote
0answers
66 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 ...
2
votes
1answer
41 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. ...
1
vote
0answers
131 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 ...
4
votes
1answer
63 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
1answer
53 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 ...
0
votes
1answer
50 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
1answer
28 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 ...
1
vote
1answer
62 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
1answer
45 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 ...
2
votes
0answers
27 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 ...
4
votes
2answers
55 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 ...
1
vote
1answer
35 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 ...
3
votes
1answer
196 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 ...
2
votes
0answers
77 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 ...
2
votes
1answer
81 views

Blocking requests within Express

Is this the correct way to block requests in Express? app.js ...
2
votes
1answer
44 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 ...
4
votes
2answers
209 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 ...
3
votes
2answers
81 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 ...
2
votes
0answers
22 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: ...
1
vote
0answers
16 views

Node Express App - Create structure around incoming payload [closed]

I am working on a simple NodeJS express app that accepts an incoming payload from a few different systems. There is a single route that ships the data off to another method and waits for the promise. ...
2
votes
0answers
2k views

Initializing a Node JS Express Application with OOP [closed]

Overview I am attempting to learn Node JS with Express by creating a project. I have seen many examples of setting up an express.js application with functional based programming, like so: ...
4
votes
1answer
37 views

Better code for error handling in NodeJs and Express

I have this code for a post request, when the user wants to change his password. Because of all the cases and the following page renders the code came out really ugly. Is there a better way to ...
2
votes
0answers
33 views

The modularization of the Express entry point

I've been working on a project to make myself more comfortable with NodeJS, especially Express and TypeScript. Searching and reviewing a lot of approaches of the people, providing bootstraps for it, I ...
2
votes
2answers
559 views

Retrieve a city list for a country and state

The code below is working properly but how do I make this code faster and more efficient. How do I perfect this code? Let's assume I have 1000 country, state and city records in a mongodb collection. ...
4
votes
0answers
38 views

Get current user middleware from JWT using express

I'm using Sequelize and Google oAuth for authentication, I want to create a middleware that Verifies the sent token passed in the headers matches the one the user was initially signed to. Finds the ...
3
votes
0answers
50 views

Node/Express authenticate Google email address

Trying to set up express server that will authenticate a user's Google email before proceeding. The code below works, but is there any way to make it more elegant? The whole ...
4
votes
1answer
962 views

Node.js http retry do while mechanism

I have implemented a simple do/while loop to handle a http request to a third-party. I don’t know when the data I receive will have elements in its array so I retry up to 10 times until the array ...