Marc Rasmussen
Marc Rasmussen

Reputation: 20565

Node js express is installed however still throwing not found error

i have installed express using:

npm install express -g

Now when i call:

npm install express

i get the following result:

    /home/marc/node
└── express@4.11.1 

So when i want to run my hello world script:

    var express = require('express');
var app = express();
app.get('/', function(req, res){
    res.send('Hello World');
});

app.listen(3000);

i still get the following error:

    Marc node # node /home/marc/nodejstest/server.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'express'
    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> (/home/marc/nodejstest/server.js:8:15)
    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)

Can anyone tell me what might be the problem here?

my npm list:

    Marc node # npm list
/home/marc/node
└─┬ express@4.11.1
  ├─┬ accepts@1.2.2
  │ ├─┬ mime-types@2.0.7
  │ │ └── mime-db@1.5.0
  │ └── negotiator@0.5.0
  ├── content-disposition@0.5.0
  ├── cookie@0.1.2
  ├── cookie-signature@1.0.5
  ├─┬ debug@2.1.1
  │ └── ms@0.6.2
  ├── depd@1.0.0
  ├── escape-html@1.0.1
  ├─┬ etag@1.5.1
  │ └── crc@3.2.1
  ├── finalhandler@0.3.3
  ├── fresh@0.2.4
  ├── media-typer@0.3.0
  ├── merge-descriptors@0.0.2
  ├── methods@1.1.1
  ├─┬ on-finished@2.2.0
  │ └── ee-first@1.1.0
  ├── parseurl@1.3.0
  ├── path-to-regexp@0.1.3
  ├─┬ proxy-addr@1.0.5
  │ ├── forwarded@0.1.0
  │ └── ipaddr.js@0.1.6
  ├── qs@2.3.3
  ├── range-parser@1.0.2
  ├─┬ send@0.11.1
  │ ├── destroy@1.0.3
  │ ├── mime@1.2.11
  │ └── ms@0.7.0
  ├── serve-static@1.8.1
  ├─┬ type-is@1.5.5
  │ └─┬ mime-types@2.0.7
  │   └── mime-db@1.5.0
  ├── utils-merge@1.0.0
  └── vary@1.0.0

Upvotes: 2

Views: 2277

Answers (1)

khollenbeck
khollenbeck

Reputation: 16157

As discussed in chat, you will want to install express local instead of global.

Local install and save to package.json:

npm install express --save

Express Docs:

http://expressjs.com/

Also Note: the following command will help you determine which packages are globally installed. Global installs are okay, but sometimes there is some extra ground work needed. (IE, adding appropriate paths to your system paths)

To see global packages:

npm list -g --depth=0

Global vs Local:

Some extra reading on global vs local.

https://nodejs.org/en/blog/npm/npm-1-0-global-vs-local-installation/

Upvotes: 2

Related Questions