Having trouble making a POST request from Alamofire to ExpressJS

My backend server is NodeJs / ExpressJs running on Ubuntu 18.04.3 LTS. When I send AJAX GET or POST requests from the front-end (JavaScript) or through POSTMAN, everything works perfectly as expected. However, when I make a POST request using Alamofire in Swift, the data being sent to the server is empty.

In my NodeJs server, I am using formidable to parse FormData bodies. On the front-end (JavaScript), I am sending data using the FormData API with headers set to content-type: false. Despite setting different content types in the headers while making a POST request from Alamofire:

  1. content type as false
  2. content type as multipart/formdata
  3. no content type specified

the issue persists with empty data being sent and received by the server.

Below is an example of the Alamofire code snippet used:

// Inserted Alamofire code goes here

In ExpressJs, I have implemented body parsers for FormData processing:

app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
app.use(bodyParser.json({ limit: '50mb' }));

I am also utilizing the formidable module to parse the request body.

The error I am encountering in Alamofire indicates a timeout during the request:

NSURLErrorDomain Code=-1001 "The request timed out." ... 
Error Domain=kCFErrorDomainCFNetwork Code=-1001 ...
NSErrorFailingURLStringKey=https://apis.example.com/apis/feed/create-post

Additionally, I have added console logs to track incoming requests in the backend:

console.log('fields', fields);

This particularly occurs in the route:

router.post('/create-post', postCont.createPost);

which shows that no data is being passed to the backend endpoint. Any insights into why the data is not being received at the API endpoint would be greatly appreciated. Thank you.

Answer №1

After swapping out pm2 for nodemon, everything began to function properly. It appears that the issue lies with pm2.

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

Compatibility of NodeJs Passport package with Linux operating systems

Currently, I am referencing the official documentation found at https://www.npmjs.com/package/passport for details on the Passport package. I am specifically investigating whether this package is suitable for use on a Linux operating system. If anyone ha ...

The initial Sequelize schema is being replaced by multiple new schemas

My current setup involves using Sequelize ORM to connect to two separate schemas. Within my models folder, I have organized the schema models into two folders - tenants and superadmin, each containing their respective model.js files. The index.js file with ...

I attempted to install the necessary dependencies using npm i, but unfortunately, it is not functioning correctly! Can someone please assist me with

Every time I attempt to install the project dependencies using npm, I encounter the following error: https://i.stack.imgur.com/PQVwx.png Can anyone provide assistance with this issue? ...

How to enable real-time file changes detection in sails for development

I recently embarked on a new project using Sails (built on Express and Node.js). Currently, I am initiating my server with the command: sails lift However, whenever I make changes to the codebase, I need to manually restart the server. Is there a way to ...

What is the best way to securely store my API keys on Heroku while ensuring my app can still access them?

I have recently completed developing a Node application and I am now in the process of deploying it on Heroku. Within my app, I utilize various API keys which are stored in a separate file that is accessed using exports throughout the application. The API ...

The MEAN stack consistently shows an error message of 'Invalid password' whenever a user attempts to log in

I have been working on creating a user login system in node.js with mongoose and MongoDB. Everything works fine when registering new users, but after a few successful logins, an error stating "Invalid password" starts to appear. I would appreciate any assi ...

Error Detection: Unable to modify headers after they have been sent to the user in my PassportJS application

I encountered this error while working on my code. I'm not just looking for the location of the error, but also seeking a better method to log errors so that I can identify where they are occurring in my code. Even after checking the error log, I am u ...

Node.js & Express: Bizarre file routes

It's quite strange how my local paths are functioning. Let me show you an example of my directory structure: public > css > bootstrap.css public > js > bootstrap.js templates > layout > page.ejs (default template for any page) tem ...

Establishing a connection with Taffy DB using Node.js

Currently, I am in the process of developing an application that utilizes Angular js, Node js, and Taffy DB. The main challenge I am facing involves storing the data submitted from the front-end into Taffy DB through the Node js server. var express = req ...

Issue: Unable to locate the module '/app/apps/landing/server.js'

Objective: Arranging for the launch of an app using a global docker-compose Challenge: The issue lies in starting the app, specifically with this command node ./apps/landing/server.js which fails to locate the server.js file node: internal/modules/cjs/lo ...

Issue with running 'npm install' on Windows 10 due to error ECONNRESET

Just recently, I upgraded to the latest version of nodejs (6.3.1) and npm version 3.10.3. Unfortunately, I am facing a problem where I cannot install any node package using the npm install command. Initially, I suspected it could be due to my office networ ...

How can eslint be used to enforce a particular named export?

Is there a way to use eslint to make it mandatory for JavaScript/TypeScript files to have a named export of a specific name? For instance, in the src/pages folder, I want all files to necessitate an export named config: Example of incorrect usage src/page ...

Local Node.js RestAPI functioning smoothly but encountering issues when deployed on a server

After developing a Node.js RestAPI to interact with a MongoDB database on my localhost, I now face the task of deploying it to a server for testing by users. The Ubuntu 16.04 server has been set up successfully with the necessary software (Node.js and Mon ...

Having trouble with NVM not working correctly in Ubuntu 21.04 Terminal?

Lately, I've been facing challenges with updating my Node.js version, and one method I tried was using node version manager. After downloading the install_nvm.sh file with the command curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/insta ...

Utilizing Selenium JavaScript to insert a cookie into a request

Trying to add a cookie to the request in Selenium using JavaScript. I followed the documentation at this link, but my code snippet doesn't seem to pass any cookies to the PHP script below on the server. Here is the client-side JavaScript code: var w ...

Setting up of imagemagick node module using linuxbrew

Having trouble installing imagemagick-native as it's showing an error. Tried using the following command to install: npm install imagemaick-native --save > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2c45414d ...

Running a JavaScript file with Node.js

My node.js script is named Index.js and I also have another file called bot.js. How can I execute the bot.js file using Node.js? var fs = require('fs'); const commandFiles = fs.readdirSync('./users/commands').filter(file => file.e ...

Encountering issues during the installation process of Yarn

I am facing an issue while trying to set up yarn on a new machine. When I input brew install yarn in the command line, I receive the following output: touch: /usr/local/Homebrew/.git/FETCH_HEAD: Permission denied touch: /usr/local/Homebrew/Library/Taps/ho ...

Struggling to retrieve a response from the ListUsers endpoint in OKTA using the okta-sdk-nodejs Client's listUsers function

Code snippet: async fetchUsersByEmail(email) { try { return await Promise.all([ oktaClient.listUsers({ search: email, }), ]).then((response) => { console.log(response); }); } catch (error) { ...

What sets apart dependencies, devDependencies, and peerDependencies within an NPM package.json file?

I found this documentation to be inadequate in addressing my question. The explanations provided were difficult for me to grasp. Can someone please explain it more simply, perhaps with the help of examples if necessary? Additionally, I am also confused ab ...