5

I have written a node js program which contained a method called AWS.config.update(). When I tried to run it on terminal, I got an error:

Error: Cannot find module 'aws-sdk'

Lisa
  • 655
  • 3
  • 10
  • 34

4 Answers4

11

Go to the folder where your node application is installed:

cd location/to/your/folder

And then run this to install the aws-sdk:

npm install aws-sdk

Akeshwar Jha
  • 4,516
  • 8
  • 52
  • 91
1

After npm install aws-sdk be sure that your package.json specifies the exact version of the new dependency, such as:

"dependencies": {
    "aws-sdk": "2.4.12",
dnaxxx
  • 175
  • 1
  • 8
1

Refer https://www.npmjs.com/package/aws-sdk to see various ways to install aws-sdk.

I prefer always adding dependency on package.json

"dependencies": {
    "aws-sdk": "^2.182.0"
}

and run npm install

Aniket Thakur
  • 66,731
  • 38
  • 279
  • 289
1

I was trying to achieve same thing and got same error

I had installed aws-sdk globally using npm i -g aws-sdk

Note running the node file from command line const AWS = require('aws-sdk') would not work, if there is no local node_modules folder which contains aws-sdk

Solution only for MAC

const AWS = require('/usr/local/lib/node_modules/aws-sdk');

For other OS, find the location of globally installed node_modules

Akshay Vijay Jain
  • 13,461
  • 8
  • 60
  • 73