Questions tagged [express]

Express.js is an innovative and versatile framework for developing web applications on Node.js, offering a comprehensive range of powerful features that enable seamless creation of robust web solutions.

Accessing req.body in the MEAN stack returns undefined

Currently, I'm in the process of developing my first MEAN stack application and encountering an issue. I have a Blog model where I am attempting to assign properties from the req object, but they are coming up as undefined. When I check the console log of ...

The Express application appears to be unresponsive, but the data has been successfully saved to the MongoDB database. An error with the

Currently, I am delving deeper into the MERN stack and working on a straightforward CRUD application utilizing it. One of the recent additions to the app includes validators implemented through express-validator for handling requests. However, an issue ari ...

Express (generator) is failing to load custom scripts located in the public folder

I'm new to node and express and I'm facing a problem. I want to load a custom script.js from the public folder, but it's not loading. There are no errors in the console or anything in the network tab. When I try to access the URL localhost:3 ...

Utilizing app.locals with .findOne in Mongoose: A Step-by-Step Guide

I am trying to locate the currently logged in user and save their information to app.locals for access in any view. In my server.js file, I have set up the following: app.use(ensureAuthenticated, function(req, res, next) { User.findOne({ _id: req.sessi ...

The app.get() method in Node JS and Express requires three parameters, and I am seeking clarification on how these parameters work

Hey there, I'm new to this and have a question regarding my code using passport-google-oauth20. app.get('/auth/google/secrets', passport.authenticate('google',{failureRedirect: '/login'}), function(req,res){ res.redirec ...

Encountering a Node Js post handling error with the message "Cannot GET /url

This is my ejs file titled Post_handling.ejs: <!DOCTYPE html> <html lang="en" dir="ltr"> <head> <meta charset="utf-8"> <title>POST-Handling Page</title> </head> <body& ...

What is the best way to eliminate specific elements from an array of objects in MongoDB aggregate based on a condition?

I have a database of documents called ChatRooms stored in MongoDB with the following structure: { _id: ObjectId('4654'), messages: [ { user: ObjectId('1234'), sentAt: ISODate('2022-03-01T00:00:00.000Z') ...

What steps should I take to create code that can generate a JWT token for user authentication and authorization?

I'm struggling to get this working. I have a dilemma with two files: permissionCtrl.js and tokenCtrl.js. My tech stack includes nJWT, Node.js/Express.js, Sequelize & Postgres. The permission file contains a function called hasPermission that is linked to ...

Pass information submitted through a JavaScript prompt to an expressjs endpoint

I'm currently facing a challenge in extracting the value from my prompt in order to modify a category using a JavaScript function. Typically, I would rely on a form to pass variables to the request.body, but that's not an option here. This is what my code ...

The configuration settings for Express are not functioning properly

Initially, I utilized the following code: app.configure( function(){ app.use(express.static(__dirname, '/')); }); Later, I realized that it was an outdated version. So, I switched to: var env = process.env.NODE_ENV || 'development&apo ...

What is the optimal ranking system for learning in Mongodb using Node.js and Express? How can we best utilize these

1 - What is the recommended order for learning (Mongo db,Node.js,Express)? 2 - Is this platform compatible with both web and mobile devices? 3 - Can you explain the functionalities of the programs? 4 - I'm planning to integrate it into my Flutter mobile ...

The array is present both before and after the res.json() call, however it appears empty in the response

When using Express to send a json response with res.json(), I am experiencing an issue where the value of records in the object sent via res.json() is empty. My code snippet looks like this: stats.activities(params).then(res => { processActivities ...

Even though I have successfully compiled on Heroku, I am still encountering the dreaded Application Error

Looking for help with a simple express/node application to test Heroku? Check out my app.js: const express = require('express') const app = express() const port = '8080' || process.env.PORT; app.get('/', function (req, res) ...

The ReactJS/Express landing page fails to display upon initiating the server.js file

Is there a way to set home as the landing page? I'm unsure of how to connect server.js to my landing page or if I should link to App.js instead. Currently, when I execute node server.js through the command prompt, it displays the following. My React compon ...

Using Promise to manipulate objects and arrays returned from functions

https://i.stack.imgur.com/jvFzC.png router.get('/', function (req, res, next) { var size = req.params.size ? parseInt(req.params.size) : 20; var page = req.params.page ? req.params.page>0 ? (size&(parseInt(req.params.page)-1)) : 0 : 0; ...

After deploying my Node.js/Express.js application to AWS Lambda, I encountered a bcrypt error

I'm currently facing an issue with getting my express.js app to run on AWS Lambda. Despite successfully deploying it using the serverless framework, I encounter a 500 internal error when testing requests. The log displays the following error message: ...

Analyzing nested arrays for email addresses using Node.js

I need help extracting key/value pairs from a nested array submitted by Angular to a Node.js server in order to populate a confirmation email. I have tried using var email = req.body.email for the top-level items and var cost = req.body.detail.cost for dee ...

Filtering relations in TypeORM can be achieved by using various query criteria

Hello, I have a couple of questions regarding TypeORM in TypeScript. Using Find() Only: I have two tables in my database - Users and Sessions. I am interested in retrieving a specific User along with all their Sessions where the sessions_deleted_at column ...

Is there a way to modify the URL in a Node.js request using JavaScript?

Is there a way that I can modify the API 'keyword' parameter to show different results each time it is accessed? Specifically, I am looking to achieve this with the following endpoint: http://localhost:3009/api/get-products/?keywords=naruto. app.get( ...

"Storing user information during a session in Node.js with Express and Socket.io

I am currently testing out this code snippet that I found online: var io = require('socket.io'), express = require('express'), app = express(), server = require('http').createServer(app), connect = require('express/node_ ...

The Query.formatError message indicates that there is an issue with the 'users.email' column in the where clause of the database query

I'm having some trouble with a piece of code. Here's my signup function : exports.signup = (req, res) => { // Adding User to Database console.log("Processing func -> SignUp"); User.create({ name: req.body.name, username: req.body.username, ...

When using Node.js and Sequelize, the findAndCountAll method does not function properly if it includes both the "include" and "where: array[]" options, along with offset and limit parameters

Currently, I am facing an issue while trying to retrieve paginated messages from a database by providing the IDs of different chats. The query works fine without specifying the limit and offset parameters. However, as soon as I include the limit and offset ...

Stuck in the midst of an AWS Amplify build due to issues

I've created a small web application using Node.js Express, HTML, and CSS. It runs locally with the command "npm start app.js", but I'm facing issues when trying to deploy it as a serverless application on AWS Amplify. Here's the build log ...

ensuring case sensitivity in URLs using node.js with express

Is there a way to make URL's case sensitive in my code? app.get() app.get('/([a-z]{2}/)api*', function(request, response){}); In the current setup, this app.get() function matches both /EN/api and /eN/api. How can I modify it to only match lower case URL ...

Running tasks in the background with Express.js after responding to the client

Operating as a basic controller, this system receives user requests, executes tasks, and promptly delivers responses. The primary objective is to shorten the response time in order to prevent users from experiencing unnecessary delays. Take a look at the ...

Transferring information from a React Native app to a Node.js server using Express

Looking for advice on transferring data between React Native and Node.js (Express)? I'm currently developing an app using React Native and Node.js with Express, but struggling to establish communication for data exchange. Any tips would be greatly appreci ...

I am curious as to why Helmet is preventing access to YouTube videos in my Express application that utilizes an embedded YouTube player

In developing my Express app, I allowed users to post YouTube videos embedded with iframe elements in the relevant view using the YouTube embedded player. However, upon attempting to deploy the app, I encountered an issue after adding Helmet with its recom ...

What is the best way to send JSON data from Express to a JavaScript/jQuery script within a Pug template?

Currently, I am facing a challenge in passing JSON data from an Express route to a .js file located within a .pug template. I have been attempting to solve this issue using the following method: The router: // Office Locations router.get('/office_lo ...

"Integrate information from a Node.js source into an already existing HTML document

I am new to node.js and have a question regarding my server.js file: var express = require('express'); var cors = require('cors'); var app = express(); var path = require('path'); var request = require('request'); v ...

Can you explain the purpose of the express.favicon() function?

Curious minds want to know the purpose of express.favicon(). After searching, I still haven't found a clear explanation. Can anyone shed some light on this? app.use(express.favicon()); I came across information that this command ignores GET requests for ...

The only thing you can see in MongoDB output is the objectid

Trying to save data in mongodb using an open schema. After making a post request, the only thing showing up in the database is the objectid. As someone new to MongoDB and Node.js, I'm struggling to identify where my mistake lies. // <---------server. ...

The Inverisfy Express utility seems to be having trouble connecting to the web socket server for socket.io

import 'module-alias/register'; import 'reflect-metadata'; import sourceMapSupport from 'source-map-support'; import { LIB_ENV_CONFIG, logger } from '@sn/shared'; import { AppServer, IExpressMiddleware, InversifyFactory } from '@sn/server'; import { AsyncC ...

Can you explain the benefits of using Karken.js to enhance the security and scalability of Node.js applications?

After reviewing multiple presentations and slides discussing how PayPal utilizes Karken.js within its Node.js Stack for enhanced security, it seems that it also integrates well with dust.js. However, the pressing inquiry remains: is this simply a tool to ...

View the picture in a web browser

Currently, I am faced with the challenge of displaying an image that is stored in an MSSQL database created by another person. The column was originally of type IMAGE, but I converted it to varbinary(MAX) using Sequelize. Although I lost some data during ...

Experimenting with the use of express route functions

Attempting to verify if res.json() is being invoked within an express get method. The get method in question waits for a promise before executing res.json(); Below is the controller method: function get(req, res, next) { Service .doImportan ...

What could be causing the createReadStream function to send a corrupted file?

My current task involves generating a file from a URL using the fs module to my local system. Initially, everything seems successful. However, when attempting to post this file into a group using the createReadStream() function, I encounter an issue where ...

Utilizing relative URIs in Node.js request library

I've encountered an issue with my code where node.js is unable to resolve the url: const request = require('request') const teamURL = `/users/${user._id}/teams`; const req = request({ url: teamURL, json: true }, function(error, response, body) ...

Automatically update and reload Express.js routes without the need to manually restart the server

I experimented with using express-livereload, but I found that it only reloaded view files. Do you think I should explore other tools, or is there a way to configure express-livereload to monitor my index.js file which hosts the server? I've come ac ...

Configuring the Port for NodeJS Express App on Heroku

Currently, I am in the process of hosting my website on Heroku and configuring everything to ensure my app is up and running smoothly. However, each time I attempt to submit the form, undefined errors occur. For more details on the Undefined Errors and Co ...

The Node server is mistakenly displaying my HTML file instead of loading the necessary Bootstrap CSS and JavaScript files

My attempt to locally serve bootstrap via an npm-installed package is not going as expected. Despite my efforts, Node seems to be serving my html file instead of the necessary bootstrap CSS and JS files, leaving me puzzled. To ensure accessibility, I have ...

I am facing difficulties in inserting information into the MongoDB database

I've encountered an issue while trying to add user data to my MongoDB database locally using post requests on Postman. Despite having an API set up in the userRoute file to handle these requests, no data is being added. Below is the code snippet: const Use ...

Having difficulties accessing the /playlists route with express and app.get in my code

I am encountering a 404 status code error when trying to access app.get('/playlists'). The browser displays "cannot GET /playlists" and I can't seem to figure out why. Here is the code I am using: var express = require('express'); // Express web server ...

Is it time to reconsider saving sessions in Node.js?

Here is the provided code snippet: app.get('/vklogin', function(request, response) { console.log('Authorizing via "Vk.com" social network'.green); var url_parts = url.parse(request.url, true); var query = url_parts.query; var data = querystring.stringify ...

Struggling to successfully update columns in postgresql using knex.js

Encountering a very peculiar issue during updates where I don't receive any response - no errors, warnings, success messages - it's as if nothing is changing. The request seems to be stuck in an infinite loop, always loading. I am using knex.js f ...

How can I send back multiple error messages from a pug template in a node.js application with Express?

I am currently working on validating inputs from a form on a Node.js web server using Pug.js and Express.js. The issue I am facing is that when there are multiple problems with the user's input, only the first error is displayed to the user. How can I mo ...

What is the reason for storing a base64 string as an Object in a MongoDB database?

I am facing an issue with storing a product detail on the mongoDB database. When I try to save it, mongoDB stores a property imageSrc as an object instead of a string. Here is my database This is my angular service And this is my express server request ...

Troubleshooting CSS pathing problem in Node.js web app hosted on A2 Hosting

I am currently learning node.js and still relatively new to it. Please excuse me if my first question is inefficient or poorly formatted. I am trying to upload a one-page test to explore A2's node.js service. Following tutorials from A2 on creating a ...

Does Express middleware allow passing errors to the next function in order to handle them?

According to the article on the Express website Writing Middleware Typically, the next function does not require any parameters. However, serve-static middleware sometimes passes an error to the next() function in its implementation. Should errors be pas ...

Configuring multiple HTTPS servers to listen on a single port in Node.js

By neglecting to specify a protocol, the code snippet below will establish an HTTPS server utilizing TLS 1.2: var options = { key: fs.readFileSync("security/server.key"), cert: fs.readFileSync("security/server.crt") }; https.createServer(options, ...

The node module.exports in promise function may result in an undefined return value

When attempting to log the Promise in routes.js, it returns as undefined. However, if logged in queries.js, it works fine. What changes should be made to the promise in order to properly return a response to routes.js? In queries.js: const rsClient = req ...

Setting cookies with NextJS Route API post middleware

@ Using NextJS 13.3 with App Dir and API Routes. I am currently working on implementing an authentication system using NextJS with my external NodeJS backend. The process involves the frontend sending credentials to the backend, which validates them and r ...

Shortcut Express Lane and Socket io

Recently, I configured my socket io connection to send information to the frontend and receive responses from the client. The data is successfully saved as well. However, it seems unnecessary to initialize socket io in the server.js file when its function ...

Ways to selectively deactivate client-side functionality

I have implemented a server-side rendered app with transitions, including a 404 error page that I placed in a lazy module to avoid increasing the size of loaded JavaScript. While this setup is functioning correctly, there is some flickering when the clien ...

Generating a file using buffer information in node.js

From the front-end client side, I am sending a file to the server. On the server-side, the data received looks something like this: { name: 'CV-FILIPECOSTA.pdf', data: <Buffer 25 50 44 46 2d 31 2e 35 0d 25 e2 e3 cf d3 0d 0a 31 20 30 20 6f 62 6a 0d 3c ...

Exploring Passport.SocketIo: A Guide to Retrieve a Roster of Active Users Using NodeJS, Express, and Passport

After successfully setting up the sessionStore with MongoStore, every login is functioning properly and sessions are being securely written to the database without any errors. To integrate Passport with Socket.IO, I am utilizing the package available at gi ...

Node.js returned null values when using the post method

After submitting the form, the form field values are not being sent using the post method. Below is the code in the index.html file: <form method="POST" action="http://localhost:4000/insertion"> <div class="form-group ...

After clicking on the checkbox, req.body.task becomes undefined

Whenever I click on the checkbox, the value of req.body.task returns as undefined. <input type="checkbox" name="task" autocomplete="off" checked="" onchange="onToDochange({{id}})"> This function is triggered by a change event on the checkbox and it ...

error 404 when sending a xhr request in node and react js

I am currently developing a basic login page in React that needs to connect to a database through an AJAX call to a Node.js file. Here is the Node.js code I have implemented: var express=require('express'); var app=express(); var db=require('./db'); var ...

Troubleshooting lpush errors in Node.js with Redis

I'm currently developing a web application using node.js and redis. The goal is to store each incoming request in a redis queue before saving it into a database. However, I keep encountering an error whenever the program executes the lpush command. Be ...

What's the best way to implement a validation check in Joi to ensure that the new password is not the same as the

Currently, I am in the process of creating Apis utilizing NodeJS and ExpressJS with Joi for schema validation. In one instance, I have a resetUserPinCode controller where I need to ensure that the oldPinCode and newPinCode values are not identical: const r ...

What could be causing my Fetch GET Request to hang in Node.js?

Having trouble with the getDocuments request in my code. It never seems to complete and stays pending indefinitely. What could be causing this issue? App.js import React, { useState, useEffect } from 'react'; import Grid from './Grid'; import apis from '. ...

Tips on how to efficiently store and access specific routes that are fetched from disk in Express.js

In my Express.js API, I have several routes that load static content from the filesystem. For example: GET /locale?lang=en - This route loads en.json from the drive and converts it into a JSON response. I am curious if Express.js has built-in caching for ...

Please wait for the serverside validation to finish before inserting data into the database

I'm still getting the hang of working with Node.js and JavaScript on the server side. Right now, I'm trying to validate user input and set default values if needed. However, when I run my validation process, the JSON object shows up in the databa ...

By enabling the "useNewUrlParser" and "useUnifiedTopology" properties to true in the MongoDB connection URL, you can prevent the need for a catch block in a promise function

Within my code, I have utilized mongoose to establish a connection with a MongoDB URL. In order to prevent the occurrence of "DeprecationWarning", I have configured parameters such as "useNewUrlParser", "useUnifiedTopology", "useFindAndModify", and "useCre ...

"Master the art of using express and jade to loop through data and generate dynamic

Hey there! I have a question regarding node.js. When working with express, we typically have multiple files such as app.js, index.jade, index.js, and server.js where most of the server logic resides. Let's say we have two objects defined in server.js: my ...

Struggling with Setting Up a MongoDB Database Using Mongoose

My goal is to set up a database in MongoDB using npm Mongoose and Robomongo as my GUI. I followed the MongoDB Quickstart Docs from http://mongoosejs.com/docs/index.html, but encountered an issue where the database wasn't showing up in Robomongo. Essen ...

Route.param query triggered callback

I have a set of routes on my server for retrieving post information and media: // Retrieve post information (description and tags) router.get('/:post_id/information', function(req, res) { User.findById(req.params.post_id) .select('data.title.text ...

Exploring Unanchored Substring Queries in Loopback API

Searching for a solution to implement a basic substring query using the loopback API for a typeahead field. Despite my efforts, I have not been able to find a clear answer. I simply want to input a substring and retrieve all brands that contain that subst ...

Switching the GET method to DELETE in nodeJS can be accomplished using an anchor tag

Let's say I have a link in my EJS file like this: <a href="/user/12">Delete</a> In my route file, I have the delete code set up like this: router.delete( '/user/:id', function ( req, res ) { // code for delete operation }); My question i ...

What is the method to retrieve body in express.js GET call?

When using sails.js framework, which internally utilizes express.js, I encountered an issue while sending a body in a GET request. The command I used was: curl -u username:password -i -H "Accept: application/json" -X GET -d "msisdn=32323" http://localhost ...

dynamic query approach for MongoDB with Express and NodeJs

Currently, I am developing an API using MongoDB, Express, and Node.js. So far, my progress has been good as I am able to query for a single record by ID, search for a specific field, delete, add, and more. However, I am now in search of a method that can ...

What is the best way to mount a node-oidc-provider on a specific mountPath in an ExpressJS application?

For my project, I am utilizing the node-oidc-provider library (version v6.29.3) to create a basic OIDC Connect mock-service. However, I've encountered difficulties when attempting to mount the provider using a specific mountPath. While everything functions ...

"Encountering an issue where the route function in Passport and ExpressJS is not being

When using passport for admin authentication, I am facing an issue where the redirect is not calling my function. Consequently, all that gets printed on login is [object Object] Here is my code: app.get('/admin', isLoggedIn, Routes.admin); app.ge ...

Route all Express JS paths to a static maintenance page

Need help with setting up a static Under construction page for an Angular Web App with Express Node JS Backend. I have a function called initStaticPages that initializes all routes and have added a new Page served via /maintenance. However, when trying to ...

Encountered a problem while attempting to post in Angular, receiving an error message stating "net::ERR

I recently started learning Nodejs. I've created an API on a local server using Mysql and I'm working on the frontend with Angular, while using Nodejs and Express as the backend. However, I'm facing an issue where my Angular app cannot conne ...