The behavior exhibited by node.js express is quite peculiar

I am currently running an Express server.

My process involves uploading an Excel File from HTML, which is then parsed by Express to perform calculations.

Each row in the Excel file contains information about a User's address.

For each address, our Express server utilizes Google Map geocoding API to determine the latitude and longitude.

Due to Google's limit of 50 requests per second to their geocoding API, I have to use setTimeout to stagger the calculations.

For instance, if the Excel file contains 50 addresses, I need to apply setTimeout to each address to prevent exceeding the rate limit.

Below is the code snippet demonstrating how to implement setTimeout for calculating latitude and longitude:

Answer №1

When your code includes the Access-Token request header, it prompts browsers to initiate a CORS preflight OPTIONS request before proceeding with the actual POST request.

For more information, you can visit https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests. Essentially, if your code is adding the Access-Token header to the request, browsers will automatically send the additional preflight OPTIONS request as part of the CORS protocol.

Postman does not trigger this extra request because it does not perform the CORS preflight OPTIONS request—this is only done by browsers for requests initiated by XHR/Fetch from frontend JavaScript code in a specific origin (which Postman is not).

Answer №2

After much trial and error, I have found a solution to the problem by including 'Access-Token' in the request body instead of the request header. This change has resolved issues with only one request being received by my server. Special thanks to @sideshowbarker for inspiring me to try this approach.

Although I still believe this issue may be a bug in Express, since it did not manifest in my local development environment, I have decided not to submit a formal report to them.

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

Unable to verify $http using passport Basic Authentication

How do I implement $http call with basic auth using Passport? I have successfully set up basic authentication with Passport on my server and can test it using POSTMAN. However, when trying to implement it in my Angular application, I am facing issues pass ...

Executing Actions Prior to Redirecting

I am working on implementing a timer process using a custom JQuery plugin that will redirect to the login page after a specific number of minutes. Additionally, when the timer reaches zero, I need to execute a task, which in this case involves making a cal ...

Rendering ReactJs on the server side versus the client side

I'm utilizing react-router for managing both server-side rendering and client-side rendering in my React application. However, I've noticed that the entry point of my app contains the following code: Router.run(routes, Router.HistoryLocat ...

Ignoring current working directory in Node.js when spawning a child process

I'm attempting to start a child process with a designated default directory. While the process is running and able to read the arguments, it still launches in the current directory instead of the one I specified in the options for cwd. Am I missing so ...

Mastering Protractor: Opening multiple sites and sending keys

My current task involves creating a script with a list of websites and corresponding amounts in a JSON format: { "URL": [{ "https://testing.com/en/p/-12332423/": "999" }, { "https://testing.com/en/p/-123456/": "123" ...

Tips on accessing data passed through res.render using Jade

I've been working with express and using res.render in the following way: res.render('myurl', { data: { account: escape(JSON.stringify(outcome.account)), user: escape(JSON.stringify(outcome.user)) }); In my JADE ...

The Correct Approach for Implementing Error Handling in a Node.js API Server

In my Node.js API server, I encountered an issue with error handling. To tackle this problem, I developed a module specifically for error handling. When in development mode, this module sends JSON objects containing errors to the API client. Here is an exa ...

Using Selenium to interact with drop-down lists using div tags instead of select tags

As a newcomer to automated testing using Selenium Web Driver, I am struggling to test drop down lists for the location type without relying on the select command. The element in question is enclosed within a div tag. I attempted sending keys but that meth ...

AngularJS textbox validation for numbers and required in repeating mode ensures that the user input is a

For more information, please visit the following link: https://plnkr.co/edit/9HbLMBUw0Q6mj7oyCahP?p=preview var app = angular.module('plunker', []); app.controller('MainCtrl', function($scope) { $scope.NDCarray = [{val: '' ...

Content sliding to the left due to modal prompt

I've searched through various questions and answers but haven't been able to resolve this issue. There's a modal on my page that is causing the content to shift slightly to the left. I've created a sample fiddle, although it doesn&apo ...

Extracting specific keys from JSON data

I am working with an array named cols: var cols = ["ticker", "highPrice", "lowPrice","lastPrice"] // dynamic The JSON data is coming from the backend as: info = {ticker: "AAPL", marketCap: 2800000000, lowPrice: 42.72, highPrice: 42.84} If I want to sel ...

Switching the scope or zone in Angular when handling events external to Angular

Currently, I am utilizing an external library within my Angular 6 application that incorporates customizable event listeners. Specifically, I am employing flowchart.js, although similar issues may arise with other libraries. In the case of flowchart.js, i ...

Server for executing front-end packages using NodeJS

Currently, I am working on a server that does not support nodeJS. I am interested in utilizing front-end packages such as the request package. Would it be necessary to have node running on the server in order to use these frontend packages? This situatio ...

Unleash the power of ExpressJS: The ultimate guide to sending data to

I am facing an issue with a post request that redirects to a new route, and here is the provided code snippet //POST login app.post('/login', urlencodedParser, function(req,res){ userLogin(req.body, function(response){ if(response ...

What can cause the reactive value to fail to update in a Vue template?

In my application, I encountered a strange issue where a h3 tag containing a title bound to a reactive data property from a Firestore database would sometimes not display properly after a page reload. Oddly enough, when accessing the page through client-si ...

Remove Vue Component from the styling of current application

We integrated a Vue component (using Vuetify) into our existing .NET MVC application. The issue we are facing is that the Vue component is inheriting all the CSS styles from the rest of the application. Here's a simplified version of the HTML structur ...

What is the process of dynamically creating a Javascript object?

I have been experimenting with creating the following custom array: var deal_info = { "1": { "deal": { "deal_id": "1", "qty": "1", "option_price_sale": "7900", "price_ship": "2500", " ...

Generate a byte array in JavaScript

How can a byte array be created from a file in JavaScript (or Typescript) to send to a C# WebApi service and be consumable by the C# byte array method parameter? Could you provide an example of the JavaScript code? The context here is an Angular 4+ applic ...

Retrieving rows from a MySQL table that contain a specified BIGINT from an array parameter

I've encountered a problem with mysql while using serverless-mysql in TypeScript. It seems like my query might be incorrect. Here is how I am constructing the query: export default async function ExcuteQuery(query: any, values: any) { try { ...

The Value Entered in Angular is Unsaved

I have encountered an issue with my app's table functionality. The user can enter information into an input field and save it, but upon refreshing the page, the field appears empty as if no data was entered. Can someone please review my code snippet b ...