I am trying to run sparkleshare-dashboard
. This is an open source project you can see it here
https://github.com/tommyd3mdi/sparkleshare-dashboard.
The project use Node.JS
and Redis
and i have no experience with both. I did setup the environment as described in the help file and then i try to run file app.js
from command line using ‘node’ command but i got this error.
Error: Cannot find module 'express-session'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (E:Importssparkleshare-dashboardapp.js:5:15)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
Maybe i didn’t provide enough information but i am expecting that may be some of you guys has done some work on sparkleshare
project and may someone can help me in this.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Open
dsm-kbl opened this issue
Dec 11, 2014
· 3 comments
Comments
I am following the book and I get this error when I try to start my server. I tried to install the module express-session but doesn’t work. It says
throw err;
Cannot find module ‘express-session’
on this line — app.use(require(‘express-session’)({ store : sessionStore }));
How can i solve this problem?
I just tried it and it worked fine for me. I have noticed two facts about npm that may help you. Sometimes there are temporary interruptions in the npm service, and sometimes just running npm install
a second time will do the trick. Secondly, even though it shouldn’t be necessary, I’ve had npm fail on me if I didn’t run it with root privileges, so you might try sudo npm install
as well. Let me know if either of these suggestions help….
Hi Ethan,
I just run npm install again and somehow it installed express-session. I got some warnings and now somehow i get a new error in this line.
app.use(vhost(‘api.*’, rest.restler(apiOptions)));
TypeError: Object # has no method ‘restler’
Any ideas?
I’m sorry its taken me so long to respond…. It looks like this is an obsolete use of the rest package…did you find that in the book or the repository?
2 participants
Содержание
- Getting an error — Cannot find module ‘express-session’ #14
- Comments
- Footer
Getting an error — Cannot find module ‘express-session’ #14
I am following the book and I get this error when I try to start my server. I tried to install the module express-session but doesn’t work. It says
throw err;
Cannot find module ‘express-session’
on this line — app.use(require(‘express-session’)(< store : sessionStore >));
How can i solve this problem?
The text was updated successfully, but these errors were encountered:
I just tried it and it worked fine for me. I have noticed two facts about npm that may help you. Sometimes there are temporary interruptions in the npm service, and sometimes just running npm install a second time will do the trick. Secondly, even though it shouldn’t be necessary, I’ve had npm fail on me if I didn’t run it with root privileges, so you might try sudo npm install as well. Let me know if either of these suggestions help.
Hi Ethan,
I just run npm install again and somehow it installed express-session. I got some warnings and now somehow i get a new error in this line.
app.use(vhost(‘api.*’, rest.restler(apiOptions)));
TypeError: Object # has no method ‘restler’
I’m sorry its taken me so long to respond. It looks like this is an obsolete use of the rest package. did you find that in the book or the repository?
© 2023 GitHub, Inc.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Источник
Why we get “error: cannot find module express”?
Express is a web framework built on Node.js
, and one that allows developers to build minimal and scalable web and mobile applications. It provides features from top performance, API designs, and extensive frameworks built on it.
For us to run Express, we need to the Node Package Manager, popularly known as npm
. However, when we run certain node applications or express codebase, we might experience the error message below
Error: Cannot find module 'express'
This error is quite common and exists because when your code ran, the express
package or module wasn’t found within its environment. In this article, we will discuss the ways you could solve this error.
Solution-1: Using npm
To do anything within Node, the npm
is your gateway to perform a lot of operations, and to solve this error, you will need it.
Normal Install
Unless you haven’t installed the express
module, you can run the following node
command
npm install express
However, if you still run the code and it gives the same issue, you can try a global installation of the express
module as you might be running your Node.js
code from a global environment within your OS.
ALSO READ: Using try catch finally in Node.js [Best Practices]
Global Install
To perform global
install of a node
module or package, you need the -g
flag. This works by place the path for the express
module within the system path
. With these, you can install the express
module globally and be able to access it without raising a not found
error message.
npm install -g express
Output:
added 57 packages, and audited 58 packages in 3s
7 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Solution-2: Check your package.json file
To solve Error: Cannot find module 'express'
error message, you can if the express
library is within your node_modules
which is available via the package.json
file.
A simple search within the package.json
can help, and you should the following within the package.json
file.
"node_modules/express": {
"version": "4.18.1",
"resolved": "<https://registry.npmjs.org/express/-/express-4.18.1.tgz>",
"integrity": "sha512-zZBcOX9TfehHQhtupq57OF8lFZ3UZi08Y97dwFCkD8p9d/d2Y3M+ykKcwaMDEL+4qyUolgBDX6AblpR3fL212Q==",
...
If the above is not present, you need to either do the normal
or global
install as stated in the previous section.
Solution-3: Set NODE_PATH for your node_modules
If express
module is present within the package.json
file and you have tried the normal and global installation, and still experience the same issues, there is another option.
This option involves setting the NODE_PATH
for your node_modules
. To carry out this operation, you need to install or update express
.
npm install express
Afterwards, you set and link the node path to the place of your node_modules
. For Linux environments, the following command works.
set NODE_PATH=your\directory\to\node_modules;%NODE_PATH%
For Windows environments, the following command works
setx NODE_PATH=%AppData%\npm\node_modules
Summary
When working within node.js
and express
, we might face Error: Cannot find module 'express'
error message. There are different reasons for this error message to be thrown at us and understanding the context matters.
If you have not installed express
, you might experience this and if the node_modules
is not set within your OS environment variables, you might experience it too. Therefore, if you try any of the options above, you will be able to deal with the Error: Cannot find module 'express'
error message.
ALSO READ: How is Nodejs single threaded? The Truth Revealed!
Further Reading
Installing Express (expressjs.com)
setx | Microsoft Learn
Node.js Error: Cannot find module express
Didn’t find what you were looking for? Perform a quick search across GoLinuxCloud
Noejs express start error: Error: Cannot find module’xxx’, which is due to the lack of module references.
For example, I used’express-session’in my code, but did not add a’express-session’ dependency to the dependencies item in the package.json file.
- D:nodejsmyapp>set DEBUG=myapp & npm start
- > myapp@0.0.0 start D:nodejsmyapp
- > node ./bin/www
- module.js:340
- throw err;
- ^
- Error: Cannot find module ‘express-session’
- at Function.Module._resolveFilename (module.js:338:15)
- at Function.Module._load (module.js:289:25)
- at Module.require (module.js:366:17)
- at require (module.js:385:17)
- at Object.<anonymous> (D:nodejsmyappapp.js:6:15)
- at Module._compile (module.js:435:26)
- at Object.Module._extensions..js (module.js:442:10)
- at Module.load (module.js:356:32)
- at Function.Module._load (module.js:313:12)
- at Module.require (module.js:366:17)
package.json file
- {
- «name»: «myapp»,
- «version»: «0.0.0»,
- «private»: true,
- «scripts»: {
- «start»: «node ./bin/www»
- },
- «dependencies»: {
- «body-parser»: «~1.15.2»,
- «cookie-parser»: «~1.4.3»,
- «debug»: «~2.2.0»,
- «ejs»: «^2.5.5»,
- «express»: «~4.14.0»,
- «express-session»: «^1.14.2»,
- «mongoose»: «^4.7.6»,
- «morgan»: «~1.7.0»,
- «serve-favicon»: «~2.3.0»
- }
- }
If you manually add dependencies to the package.json file, you need to execute under your project directory (my directory is: D: nodejs myapp): npm install
Another method is to execute: npm install module name — save
- D:nodejsmyapp>npm install express-session —save
- express-session@1.14.2 node_modulesexpress-session
- ├── on-headers@1.0.1
- ├── cookie-signature@1.0.6
- ├── utils-merge@1.0.0
- ├── cookie@0.3.1
- ├── parseurl@1.3.1
- ├── depd@1.1.0
- ├── crc@3.4.1
- └── uid-safe@2.1.3 (base64-url@1.3.3, random-bytes@1.0.0)
Remember to replace the’xxx’or’express-session’ I mentioned here with the module name suggested in the error message you encountered.