TypeError: request.post is not a function
See original GitHub issueSummary
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:
- Created 5 years ago
- Reactions:2
- Comments:5
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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