Lisa
Lisa

Reputation: 675

Error while running a Node js program

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'

Upvotes: 5

Views: 32614

Answers (4)

Akshay Vijay Jain
Akshay Vijay Jain

Reputation: 16025

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

Upvotes: 1

Aniket Thakur
Aniket Thakur

Reputation: 69035

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

Upvotes: 1

dnaxxx
dnaxxx

Reputation: 175

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",

Upvotes: 1

Akeshwar Jha
Akeshwar Jha

Reputation: 4576

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

Upvotes: 11

Related Questions