0

Ok so i am following a node.js and express tutorial. In the tutorial it reqired me to install express. so i did. But this error came up when i tried to run it.

    Error: Cannot find module 'express'
Require stack:
- c:\Users\prodi\Desktop\Personal Media\coded files\practice\node js prac 2\app.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (c:\Users\prodi\Desktop\Personal Media\coded files\practice\node js prac 2\app.js:1:17)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    'c:\\Users\\prodi\\Desktop\\Personal Media\\coded files\\practice\\node js prac 2\\app.js'
  ]
}

I then tried to resolve it on my own but eventually searched it. I came across this post. node.js, Error: Cannot find module 'express'

Some of the answers included installing express again which i did and some installing locally and globally which i did but no luck.

I then saw a comment with over 33 likes that said ...and if your node_modules directory is in another place, set NODE_PATH envirnment variable:

 set NODE_PATH=your\directory\to\node_modules;%NODE_PATH%e here

I then tried this but it just keeps giving more errors.

I copied relative and whole path from my app.js files which is the file i want... I tried all of these:

set NODE_PATH=C:\Users\prodi\Desktop\Personal Media\coded files\practice\node js prac 2\app.js

set NODE_PATH=/node js prac 2\app.js

set NODE_PATH=Users\prodi\Desktop\Personal Media\coded files\practice\node js prac 2\app.js

set NODE_PATH=/node js prac 2/app.js

set NODE_PATH=./node js prac 2/app.js

all of them either gave a syntax error or this error

Set-Variable : A positional parameter cannot be found that accepts argument

'files\practice\node'. At line:1 char:2

  • set NODE_PATH=C:\Users\prodi\Desktop\Personal Media\coded files\prac ...
  •  + CategoryInfo          : InvalidArgument: (:) [Set-Variable], ParameterB
    indingException
     + FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShel
    l.Commands.SetVariableCommand
    
    

So i searched that error and came to this post...https://stackoverflow.com/questions/51459313/cd-program-files-error-positional-parameter-cannot-be-found

But most of the comments are either invalid syntax or things that dont work for me. Can you guys help?

  • `npm install express` in the correct directory should be enough – Konrad Oct 13 '22 at 06:40
  • i think i did that thats what im trying to do..did i do it wrong ? If i didit wrong how do i do it –  Oct 13 '22 at 07:01

0 Answers0