I'm learning node. I've initialized a project with npm. I installed express, and everything looks alright.
npm list outputs this:
package.json looks like this:
And the project is structured like this:
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:
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();