I'm new with nodejs and trying to learn it. I have installed node framework express as global module by command:
$ sudo npm install express -g
This works correctly and I have it in /usr/lib/node_modules
. Then I'm creating a new project on express:
$ express app
But this doesn't create project folder and does not return any error code, clear node code works fine. Anybody knows how to detect and fix this error?
To solve the error "Cannot find module 'express'", install the package by running the command npm install express in the root directory of your project. If you don't have a package. json file, create one by running npm init -y . The error occurs when we try to import the express package without installing it.
js const express = require('express') // Create Express app const app = express() // A sample route app. get('/', (req, res) => res. send('Hello World! ')) // Start the Express server app.
Yes, install Express and other NPM components separately for each project. This way, you keep each project independent from the others and you can upgrade components in one without affecting all the others. Each project then has its own package.
found it. the npm package is actually named express-generator
sudo npm install -g express-generator
you can then use
express mytestapp
that results in :
olivier@****:~/workspace$ express mytestapp
create : mytestapp
create : mytestapp/package.json
create : mytestapp/app.js
create : mytestapp/public
create : mytestapp/public/javascripts
create : mytestapp/public/stylesheets
create : mytestapp/public/stylesheets/style.css
create : mytestapp/routes
create : mytestapp/routes/index.js
create : mytestapp/routes/users.js
create : mytestapp/views
create : mytestapp/views/index.jade
create : mytestapp/views/layout.jade
create : mytestapp/views/error.jade
create : mytestapp/bin
create : mytestapp/bin/www
create : mytestapp/public/images
install dependencies:
$ cd mytestapp && npm install
run the app:
$ DEBUG=my-application ./bin/www
Cheers ! Olivier
Source : http://expressjs.com/guide.html#executable
For me the solution was simply to install the nodejs-legacy package:
sudo apt-get install nodejs-legacy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With