Is there a way to incorporate the 'window' into middleware when using Express?

I am using middleware to retrieve data from a cookie with the help of vue-cookies.

  try {
      if (window.$cookies.get('region')) {
        res.setHeader('Set-Cookie', [
          `region=${window.$cookies.get('region')};path=/`
        ])
      } else {
        res.setHeader('Set-Cookie', [
          `region=${process.env.DEFAULT_REGION};path=/`
        ])
      }
    } catch (e) {
      console.log(e)
    }

Everything is functioning correctly, but in the server terminal, I am seeing this error:

ReferenceError: window is not defined
    at server.js:3102:7
    at promisify (server.js:2522:15)
    at middlewareSeries (server.js:2501:10)
    at server.js:2502:12
    at async module.exports../.nuxt/server.js.__webpack_exports__.default (server.js:1964:3)

Should I just ignore this error, or is there a way to fix it?

Answer №1

I was able to retrieve the data from this field by simply using req.cookies.region

Appreciate all the assistance, everyone!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

NodeJS Server - Implementing Configurations for Multiple URL Rewrites

Seeking to utilize a NodeJS server as a quick fix to test some AngularJS apps that were developed in a .NET environment (running on a mac). Both applications make use of the <base> tag and have rewrite rules in the web.config file to prevent 404 erro ...

Pass data from JavaScript to PHP using AJAX

Using Leaflet to display a map, I have incorporated ajax into my onEachFeature function in order to retrieve variables to pass to PHP. Here is the code snippet: function onEachFeature(feature, layer) { layer.bindPopup(feature.properties.IDLo); layer. ...

What is the best way to synchronize the image dimensions and source when dynamically loading images?

I am facing an issue with a function that updates images by altering the src and css (width/height) of an IMG tag within the document. Below is a simplified example to demonstrate the problem: updateImage = function(src, width, height) { $("#changeMe"). ...

Opensuse is having trouble running a recently created React/Node.js project

Currently, I am in the process of learning Express and react. Initially, I was able to successfully run a react app. However, when starting a new web app yesterday, I encountered issues preventing a freshly created react app from crashing. My System: o ...

Picking out specific elements from a component that is rendered multiple times in a React application

One of the challenges I face involves a component called card, which is rendered multiple times with different data. Here's how it looks: { this.state.response.reminders.map((item,i=0) =>{ return <Card key={i++} reminder={item} deleteRem={th ...

Handling conditional statements in JSX

Here is an example of my straightforward component: function Messages(props) { return ( <View> <View style={styles.messageWrapper} > <View style={styles.isNotMine}> <View style={s ...

Understanding how to break down intricate JSON strings into classes using either VB or C# programming languages

I have a JSON string that needs to be parsed and eventually stored in database tables. My plan is to parse it into VB .NET classes (objects) and then store the data in the tables. I have Newtown imported into my .NET environment, but I'm not very fami ...

What tools do Sketchfab and Thangs utilize to display 3D models?

My website functions as a digital library for a particular niche of 3D models. However, I've noticed that the performance on mobile devices when using modelviewer to display glb files is quite poor. Frequently, the page crashes and reloads unexpectedl ...

Troubleshooting the issue with utilizing the ng-repeat directive to loop through images in Angular JS

Embarking on my initial website development journey with Java and Spring Boot, I've hit a stumbling block in the front-end realm. Being a newbie, I'm struggling to identify and resolve the issue at hand. Problem title: How do I ...

Utilizing ObjectLoader for loading JSON featuring a BufferGeometry with multiple materials is not successful

I have successfully crafted a sphere using multiple materials in the following manner: const materials = [ new THREE.MeshPhongMaterial({}); new THREE.ShaderMaterial({ visible: false}); ] const geometry = new THREE.SphereBufferGeometry(2,100,100); ...

The AJAX callback is unable to access the method of the jQuery plugin

I have a scenario where I am fetching data from an AJAX response and attempting to update a jQuery plugin with that value within the success callback: $.ajax({ url: '/some/url', type: 'GET', dataType: 'json', succ ...

When the button is clicked, dynamically fetch data from a MySQL database using PHP without the need to refresh

I have a .php page where I am displaying a table from my MySQL database using PHP based on a cookie value. On this same page, I have implemented a feature that allows me to change the cookie data without having to reload the entire page by simply clicking ...

Creating a TypeScript class with methods to export as an object

Just dipping my toes into Typescript and I've encountered a bit of a challenge. I have a generic class that looks like this: export class Sample { a: number; b: number; doSomething(): any { // return something } } My issue ari ...

Using the req object in Express triggers an UnhandledPromiseRejectionWarning

After referencing Google's Datastore tutorial, I've incorporated the code and made use of Promises and await where applicable. While working with the req object in express, everything seemed fine until it appeared empty in this scenario. An erro ...

Click to stay in the background

I am currently facing an issue where opening a new tab on click redirects the focus to the child window instead of staying in the current window. I would like the popup to open without blocking and allowing me to maintain focus on my current window. The c ...

Preventing an RxJS Observable interval: A step-by-step guide

I am facing a unique scenario where I am using an RxJS interval, but I might need to abruptly stop it at any point. I thought there would be a simple method like cancel() or stop() similar to clearTimeout for intervals. Is there a way to stop an interval o ...

NodeJS with Selenium - Attempting to Choose a Button

The HTML <button class="RCK Hsu USg adn gn8 L4E kVc iyn S9z Vxj aZc Zr3 hA- Il7 hNT BG7" tabindex="0" type="submit"> <div class="KS5 hs0 mQ8 un8 tkf TB_"> <div class="xuA"> ...

Discovering details regarding cookies established by an external domain

Is it possible to retrieve the host address of the domain that created a cookie on my webpage? Here is the scenario I am facing: I am on "domain A" and have a script linked from "domain B". A method on "domain B" sets a cookie on my "domain A". How can ...

Issue encountered during upgrade from version 10 to version 13 in a Next.js migration: Module not found

I've been working on upgrading our old site from version 10 to version 13, and we have a custom backend built with express. However, I keep encountering a "Module not found" error when running the project concurrently, specifically when running the cl ...

What is the method to convert Javascript values from pixels to percentages?

Is it possible to change the scrolltop value dynamically based on a percentage of the user's screen size? I've been trying to achieve this using JS but haven't had any luck. Here is a link to a codepen that showcases the issue: [link] (http ...