Lets say I have this for local testing. This gets a file based on a path to the file of course. Now lets say that the img folder is actually the folder to the subdomain, and I wanted to send the image from the subdomain itself, so instead of the api requesting to the main site aka mysite.com, it would
Tag: express
Add authentication check on every child endpoint of a express router
I have a express router and I only want authorized users to access routes of that router. I am using passport middleware. So I can just add a check for req.user in every endpoint like: I can add a check in every endpoint like this but is there any better way to do this? Answer You can factor the behavior
Axios PUT request not sending all data to server JS
My problem is that I am sending an axios request with certain data, however, not all of the data is being updated in the user model. See my code below: Front-End code with axios request: User model in the backend: Update controller in the backend: Address and phone number are updating correctly, however, nati…
Unable to get __dirname value
I am using __dirname to get absolute path to GraphQL schema: I have changed module to fit ES6 module standard and __dirname now is undefined. How can I resolve path to schema? Answer There is some issue with esm + __dirname https://nodejs.org/api/esm.html#esm_no_require_exports_module_exports_filename_dirname…
Why isn’t my import being found by the esm loader?
I have a small express server and in my bin/www.ts I import my app.ts file like this: When I build my project and turn it into JavaScript using: tsc –project ./ and then run it with nodemon ./build/bin/www I get an error in my console saying: The file exists in the location I specified, I’ve check…
How we can intergrate Qr code monkey api to an express.js backend
Intergrate this for https://rapidapi.com/qrcode-monkey/api/custom-qr-code-with-logo For this code const express = require(‘express’); const http = require(“https”); const router = express.Router(); router.post(‘/’,async (req,res)=>{ console.log(“req”,req.body…
Is this bad practice for res.locals? (Node.js, express)
I was wondering if using res.locals like in this code example is bad practice or if there can occur any problems if you use it this way: Basically I: I verify the session-cookie in app.use (Im using firebase auth) I set the res.locals.userId = userId And then use the local i just set in the app.get (I need to…
Simple Tutorial code not getting data from a Login form (express js)
So I am following a YouTube Tutorial on how to set up a simple login server (channel name: web dev simplified, video: “Node.js Passport Login System Tutorial”) The code (at the stage I am at @ 14:12 mark in video) is suppose to console-log an array of a new registered user at the terminal. but I g…
Typescript’s declaration merging not working as expected using ts-node
For a project using the express-session package, I’m trying to mutate the session object by simply adding a user key. Coming from this question’s accepted answer, I understand I could use declaration merging to extend the SessionData interface, using my own interface. Looking at various open-sourc…
.env for prod and developpment with nodejs
I saw lot of different ways, some looked normal some others looked a bit more patchworked. Can we use package json script to chose our env variables ? What is the right way to do it with nodeJS and how to do it ? I have already made an .env. It contains api keys which are global for dev and