Multer module won't start

Jason picture Jason · Mar 1, 2015 · Viewed 9.3k times · Source

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.

Answer

Timothy Gu picture Timothy Gu · Mar 1, 2015

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