Node.Js: Cannot Find Module 'Request'

node.js: cannot find module 'request'

Go to directory of your project

mkdir TestProject
cd TestProject

Make this directory a root of your project (this will create a default package.json file)

npm init --yes

Install required npm module and save it as a project dependency (it will appear in package.json)

npm install request --save

Create a test.js file in project directory with code from package example

var request = require('request');
request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body); // Print the google web page.
}
});

Your project directory should look like this

TestProject/
- node_modules/
- package.json
- test.js

Now just run node inside your project directory

node test.js

Getting Error: Cannot find module 'request' even though I have added request module

This can happen when you "npm install" a dependency to the wrong folder, as I have just realised I did. I have a Vue project in the "src" subdirectory, and an index.js (Firebase cloud function) in the "functions" subdirectory.

Dependencies of the Vue project must be installed with "npm install" in the main directory. In contrast, dependencies of the Firebase cloud function must be installed with "npm install" being run in the "functions" subdirectory. I had accidentally installed the dependency in the main directory, and was breaking my head trying to understand why it was complaining that it couldn't find the dependency (googleapis) until I realised what I had done. The fix was of course to install it in the right place (so it showed up in the right package.json), and uninstall it from the wrong place for neatness.

npm uninstall request //removes the module from node_modules, but not package.json or npm uninstall --save request
npm cache clear --force
npm install --save --save-exact request@2.88.0
firebase deploy --only functions

Node.js Error: Cannot find module 'request'

Something looks wrong in your directory structure. I would nuke the node_modules directory and redo the npm command.

It's always a good idea to maintain a package.json file and see the dependencies written out

cd getFoo
npm init # answer the qestions
npm install --save request
node app.js

node.js- Cannot find module request : Windows

Have you installed request? Try running "npm i request" and then running script again. A node_modules folder should be in your directory with request module inside for node to require it. The structure of your application should be something like this

 |-- Folder name
|-- main.js
|-- package.json
|-- node_modules
|-- request

You shouldn't be using node_modules folder in your programme files folder.

firebase function https post - Error: Cannot find module 'request' problem

If you don't see the request module in your package.json, that means you probably ran the npm command in the wrong folder. You should run it from your "functions" folder, where package.json lives.



Related Topics



Leave a reply



Submit