kruparulz14
kruparulz14

Reputation: 163

node.js- Cannot find module request : Windows

I read many answers here on StackOverflow but I am still getting errors while I run my program on cmd- node main.js

I am trying to make an API call to Youtube API, Here is the code.

var request = require("request")

var url = "https://www.googleapis.com/youtube/v3/search" +
"key=XXXXX" +
"part=snippet" + "q=eminem"

request({
url: url,
json: true
}, function (error, response, body) {

    if (!error && response.statusCode === 200) {
    console.log(body) // Print the json response
    }
})

I get this error:

module.js:340
throw err;
      ^
Error: Cannot find module 'request'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Users\Usr\Desktop\main.js:1:77)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

Upvotes: 1

Views: 5246

Answers (1)

simon-p-r
simon-p-r

Reputation: 3751

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.

Upvotes: 1

Related Questions