Trouble with the "express" module with Node JS


I am learning Node JS with Visual Studio Code from Microsoft. Here is the Javascript file:


const express = require('express')
const app = express()
const port = 9999

app.get('/', function (request, response) {
  response.send('Allo de Express!')

app.listen(port, function (err) {
  if (err) {
    return console.log('Oups! Une erreur est survenue', err)

  console.log(`À l'écoute sur le port ${port}`)

I had installed «express» with this command:

PS C:\Users\jean\Documents> npm -g install express
+ express@4.16.3
added 1 package, updated 2 packages and moved 2 packages in 11.24s

PS C:\Users\jean\Documents> cd node_modules
PS C:\Users\jean\Documents\node_modules> ls

    Répertoire : C:\Users\jean\Documents\node_modules

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----       29/03/2018     14:59                bytes

There no directory for the module «express». Where is it?

When I execute the Javascript file, I get an error:

PS C:\Users\jean\Documents> node test3.js
    throw err;
Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Users\jean\Documents\test3.js:1:79)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

But the module «express» seems to be there:

PS C:\Users\jean\Documents> npm search express

NAME                      | DESCRIPTION          | AUTHOR          | DATE       | VERSION  | KEYWORDS
express                   | Fast,…               | =dougwilson…    | 2018-03-12 | 4.16.3   | express

Any help, please.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Nitin SontakkeDeveloperCommented:
I am also learning Node. From whatever I have learned somewhere, it appears that express must be installed locally.

Please refer to this stackoverlow thread.
JeanLeFrancaisAuthor Commented:

After a couple of days, I finally was able to install the "express" package. The command:

npm install express

never worked. It never created the "express" directory. In fact it even deletes when it finds it!!!

So I ran instead:

npm install express -g

The necessary 3 directories were created in the directory "C:\Users\jean\AppData\Roaming\npm\node_modules". Then I simply copied them into my local directory where the Node JS code is. It worked!


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JeanLeFrancaisAuthor Commented:
It worked.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.