Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multer module won't start

I'm writing a web app using the MEAN stack. I installed multer via npm like so:

sudo npm install -g multer

and I require it in one of my routes files:

var multer = require("multer");

I'm using nodemon and it throws the following error every time it restarts since I've added the require statement.

28 Feb 18:39:13 - [nodemon] restarting due to changes...
28 Feb 18:39:13 - [nodemon] starting `node ./bin/www`
module.js:338
    throw err;
          ^
Error: Cannot find module 'multer'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/jason/Desktop/Node/todoApp/routes/todos.js:8:14)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
28 Feb 18:39:13 - [nodemon] app crashed - waiting for file changes before starting...

I've installed mongo, node, and express all in the past two days. I'm running OS X Yosemite version 10.10.2.

like image 706
Jason Avatar asked Mar 01 '15 01:03

Jason


2 Answers

You have to install the module locally, without the -g flag:

$ npm i multer

Alternatively, you can either link the globally installed module to local directory or specify an environment variable NODE_PATH as illustrated in NodeJS require a global module/package

like image 104
Timothy Gu Avatar answered Oct 21 '22 15:10

Timothy Gu


If using typescript don't forget to install it's types

npm install @types/multer
like image 44
Auðunn Hrafn Alexandersson Avatar answered Oct 21 '22 16:10

Auðunn Hrafn Alexandersson