Home > Software engineering >  Node doesn't find local packages
Node doesn't find local packages

Time:01-15

I'm learning node. I've initialized a project with npm. I installed express, and everything looks alright.

npm list outputs this:

enter image description here

package.json looks like this:

enter image description here

And the project is structured like this:

enter image description here

with index.js just being the following:

const expressDep = require('express');
const app = express();

But when I try to execute index.js, node outputs the following:

enter image description here

What am I doing wrong ? To my understanding, node just doesn't see any definition of express, but npm tells me everything is installed correctly. What's going on ?

CodePudding user response:

How can the compiler know what is this express()?

Require is a built-in function to include external modules that exist in separate files.

If you want to use this app function you must use the variable you assigned the module. Like this:

const express = require("express");
const app = express();

or

const expressDep = require("express");
const app = expressDep();
  • Related