I know that this has been asked before but none of the solutions worked for me. Whenever I try to install express, it seems to work just fine, displaying this message:
npm WARN website@1.0.0 No description
[email protected] updated 1 package and audited 50 packages in 6.581s found 0 vulnerabilities
However, when I try to run my program that uses express:
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:889:15)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (C:\Users\darcy\OneDrive\Sutton\Website\server.js:2:15)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
code: 'MODULE_NOT_FOUND',`
Here is my code:
let express = require("express");
let account = require("accountBack");
let shop = require("shopBack")
let serverConnection = express();
serverConnection.listen(3000, () => {});
serverConnection.use(express.static("public"));
serverConnection.use(express.json());
serverConnection.post("/account", account.accountServer);
serverConnection.get("/shop", shop.sendShop);
I am using code from other files (hence the extra 2 require statements) but what they do I do not believe to be significant.
Here are the commands that I am typing in:
npm init
npm install express
node server.js
It does not appear from the error that express is gettinginstalled correctly, but I'm not sure. Is it a problem with the commands that I a typing in or something else? Any help would be appreciated.
CodePudding user response:
For the internal module, you should import like this
const account = require("./accountBack");
const shop = require("./shopBack")
Unless you publish those modules to npm
registry (private/public), then you can import like what you did.
CodePudding user response:
I had this issue once and I solved it placing express server in an unique folder separated from the rest of the program. Basically, make sure that in your project folder, you create another folder inside main folder where you will store your server.js - in that nested folder is where you wanna npm install express.