question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: request.post is not a function

See original GitHub issue

Summary

I’ve installed request via nom and have a const request = require(“request”); at the top of my file but when I run my program it says that request.post isn’t a function

Simplest Example to Reproduce

Install latest built and try to make a post request

request.post('http://' + config.devices.port["2002"] + ":3000/api/mysql", {
      json: request.body.data,
      method: "POST"
    }, (error, response, body) => {
      if(error){
        console.error(error);
        console.log(" <- Process return (REJECTED) from " + config.devices.port["2002"] + ":30301/api/mysql");
        res.send("Failed to pass process mysql to " + config.devices.port["2002"] + ":30301/api/mysql");
        return;
      }
      console.log(" <- Process return (ACCEPTED) from " + config.devices.port["2002"] + ":30301/api/mysql");
      res.send("Passed process mysql to " + config.devices.port["2002"] + ":30301/api/mysql\nWaiting for response delivery....");
      return;
    });

Expected Behavior

It is expected that request.post is infant a function/method

Current Behavior

Currently node doesn’t think that request.post is a method

Possible Solution

Not Sure

Context

I have two instances of node running on two different devices, each listening for a post request from the other, this is to create a two player game on to local machines using http requests

Your Environment

Both devices are raspberry pi one is a 3b the other is a 1a both running raspbian stretch (latest)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5

github_iconTop GitHub Comments

3reactions
computerFriendcommented, Jan 22, 2020

Hi, I think I might know the issue here: Because you are referencing request.body.data, I am assuming you have defined a “request” somewhere else in your code – which means that the npm module, ‘request’, is being overwritten by the request object you have defined.

if you import the module with another name, this may solve your problem, e.g.,

const requestModule = require('request')requestModule.post('http://' + config.devices.port["2002"] + ":3000/api/mysql", {

2reactions
ducnguyenhuy-agilityiocommented, Jul 14, 2020

Hi, I think I might know the issue here: Because you are referencing request.body.data, I am assuming you have defined a “request” somewhere else in your code – which means that the npm module, ‘request’, is being overwritten by the request object you have defined.

if you import the module with another name, this may solve your problem, e.g.,

const requestModule = require('request')requestModule.post('http://' + config.devices.port["2002"] + ":3000/api/mysql", {

I used the autosuggestion in code editor and it was auto-required request const and this issue occurred

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError: req.post is not a function - node.js - Stack Overflow
js under signup route after registering the user I want to send a verification email and a verification sms. But the smsService request...
Read more >
app.post is not a function error (Example) - Treehouse
I'm not sure why you would get an error stating that app.post is not a function. This normally happens when you try to...
Read more >
TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >
How to solve the "is not a function" error in JavaScript
js we use require() to load external modules and files. This can cause, in some cases, an error like this: TypeError: require(...) is...
Read more >
Error TypeError is not a function in Node js | Edureka Community
Hello @kartik,. Because of circular dependency, check if you have 2 classes that are requiring each other, remove one of them from requiring...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found