Link to home
Start Free TrialLog in
Avatar of JeanLeFrancais
JeanLeFrancais

asked on

Trouble with the "express" module with Node JS

Hello.

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

«test3.js»:

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
module.js:549
    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.

Jean
Avatar of Nitin Sontakke
Nitin Sontakke
Flag of India image

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.
ASKER CERTIFIED SOLUTION
Avatar of JeanLeFrancais
JeanLeFrancais

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JeanLeFrancais
JeanLeFrancais

ASKER

It worked.