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?
First thing to try is if the plugin is installed:
$ npm -g ls | grep express
If nothing is returned, try reinstalling it.
Since in this case it was still installed, the next solution was to reinstall Node entirely.
There is a great post on cleaning up Node installations here: Uninstall Node.JS using Linux command line?
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
This is what I did to get mine to work and make sure everything was working ok on Ubuntu 12.04 running Node 0.8.21 and Express 3.2.0.
First install express
sudo npm install –g express
Now check that express is working by querying it for the version:
express -V
Now I went and created an express app:
cd /usr/lib/node_modules
sudo express -s -e expressTestApp
The following was output:
create : expressTestApp
create : expressTestApp/package.json
create : expressTestApp/app.js
create : expressTestApp/public
create : expressTestApp/public/javascripts
create : expressTestApp/public/images
create : expressTestApp/public/stylesheets
create : expressTestApp/public/stylesheets/style.css
create : expressTestApp/routes
create : expressTestApp/routes/index.js
create : expressTestApp/routes/user.js
create : expressTestApp/views
create : expressTestApp/views/index.ejs
install dependencies:
$ cd expressTestApp && npm install
run the app:
$ node app
So, following the instructions it gave me, I ran the following two commands in sequence:
cd expressTestApp
sudo npm install
After just a minute it finished and I was able to open /urs/lib/node_modules/app.js and work with it. Also, running node app like it said in the instructions during the express module creation worked as well.
From a previous comment, it looks like you might have fixed it by reinstalling node, but I still hope this will help you.
Perhaps a sudo express app
might do the trick? (I see you're executing in /var/www
, which generally is off limits from regular users?)
As of Ubuntu 16.04 LTS, the problem occurs when express is installed globally. To fix this, make sure you install express to your working directory even if you have installed globally.
Use
sudo npm i express-generator --save
to save it to your working directory in every project you do.
Had this problem and fixed it easily, without having to reinstall nodejs or any other dependency.