Express doesn't work on ubuntu - node.js

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?

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

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?

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.

Related

Create vue Permission denied

I'm trying to install vue app using this command "npm init vue#latest",
But the following error occurred with me, any help :(
Note : I tried many solutions like : chmod -R 755 .npm and sudo chown -R mostafa .npm but nothing changes
maybe you could try using the vue-cli like this:
npm install -g #vue/cli && vue create hello-world
If this wouldn't work then I'd suggest to reinstall node/npm
You should probably also make a clean installation of these tools so that you don't need to run such things as administrator
In order to install vue on your machine you must first have installed nodejs ( package manager node package manager ) to which the acronym npm refers, I leave you the linux commands under :
install :
sudo apt install nodejs
shows the installed version of nodejs :
node -v
After installing nodejs try relaunching the command to install vue
if you have already installed them try with this :
add write permissions to the study folder , and not to the mostafa folder , linux only assigns permissions to the folder in the chmod command and not subfolders, try these commands :
cd home/mostafa/Dowloads
sudo chmod ugo+w study
Are you not being blocked by SELinux directives?
Try running the same command using your least privileged user (normal user).
And please avoid using the root user for everyday tasks.
You need to have installed Nodejs, vue and create-vue.
sudo apt install nodejs
npm install vue#latest
npm install create-vue#latest
Now you can run the command to start the new project with Vue.
npm init vue#latest

'express' is not recognized as an internal or external command

I am trying to start an express-generator app but I am getting "express is not recognized an internal or external command. I tried all the below
in windows CMD as administrator:
$ npm install express -g
$ npm install express-generator -g
$ mkdir myApp
$ cd myApp
$ express helloApp
the latest command was supposed to create all the express-generator related files (i.e. routes, models, views, etc.). But I am still getting the same error again and again. Any solutions would be much appreciated.
Since you are using npm < v8.2.0 you need to install it globally (v8.2.0 allows you to use npx). From their documentation:
$ npm install -g express-generator
$ express --view=pug myApp
You can change the view parameter or even exclude it. This is how I always do it and I just tested it to confirm it works for me although I am using a different version of npm and node than you are.
try this.
npm cache clear --force
$ npm install -g express-generator
$ mkdir myApp
$ cd myApp
$ express helloApp `
remember if you are installing globally you need to use sudo for linux and mac, and powershell or admin cmd to run the code. eg
$ sudo npm install -g express-generator
i solved the above error by uninstalling node js(v10.16.3) and reinstalling the current version (v12.12.0) ....followed by the known commands:
npm install express -g
npm install express-generator -g
express project_folder_name
honestly till now i couldn't find any reason for what caused this...but i suppose it was something related to my node_modules directory....
thanks Dillan and Ani for your kind help...your suggestions helped a lot....thanks :)
One other possibility - I was unable to use express-generator in vscode. I tried to use it separately in both cmd and powershell. It worked using cmd, but not powershell. Modify vscode to make cmd the default terminal and you're good!

loopback "lb4" command is not working after successfully installation of loopback CLI using "npm i -g #loopback/cli"

I have successfully installed loopback CLI using npm i -g #loopback/cli after that I'm trying to create app using lb4 app command terminal and it shows me Command 'lb4' not found.
Only lb app works for version 3 and 2 but I want to create application compatible with loopback version 4.
I had the same problem and solved it by updating to the latest version of Node.js (10.7 as of now). Then I reinstalled the LoopBack CLI with npm i -g #loopback/cli and the lb4 app command worked just fine. Also, I was executing all the commands as admin, in case it helps.
If you're having trouble creating a global link on Windows 10 (like I did).
Consider installing in the NodeJS project folder as a work-around.
Simply execute:
npm install #looback/cli --no-save
Notes:
This will install the cli without listing it as a dependency in your package.json.
This will allow you to run lb4 app only in the root folder of project where you ran the command.
This solution is not ideal since you'll have to do this for each project. However I figured it beats having to install a new version of NodeJS just for the installer to clear some cache/configuration that got messed up over a long time-period.
Upgrade your Node.JS to version 8.9 or higher.
It's a Prerequisites.
See the doc: https://loopback.io/doc/en/lb4/Getting-started.html#prerequisites
Also some time npm installs the JS module successfully but does not add in environment variable. Find the npm folder path (in my case C:\Users\user_name\AppData\Roaming\npm) and add into class path. After adding environment variable restart the command prompt.
I was also facing same problem. But then I ran the command using sudo and it worked. sudo npm i -g #loopback/cli.
sudo update-alternatives --install /usr/bin/lb4 lb4 /opt/nodejs/node-v19.1.0/bin/lb4 0
This command will be more useful to solve this problem.
You can replace nodejs path according to your system.(/opt/nodejs/node-v19.1.0/bin)

Express is not working on ubuntu

I have installed nodejs,express on ubuntu but when i type "express test" command on terminal on ubuntu, its not creating the folders etc (package.json,app.js, view folder ect).It simply prompts in the next line.
Please help
If you want to generate the scaffolding for a new express app you can use the express-generator.
First you need to install the needed module globaly.
sudo npm install express-generator -g
Then you can use this command to generate your scaffolding.
express <my_app>
More info here http://expressjs.com/starter/generator.html

Express command not working in terminal

I am kind of new to node.js. I installed node fine and it works. I can run the node command in the terminal as well as the node package manager command(npm). Working on a Mac by the way. So I installed express globally with the following command:
sudo npm install -g express
After I was done installing it globally I installed it in a small folder where I am working on a project.
sudo install express
That gave me a node_modules folder inside of my site folder. After I was done that I went to install stylus using the express command and I got the error that express is not a command.
express -c stylus
Can anyone shed some light on this issue? I also tried to link the global express to the folder where I am working on the project using the following command:
sudo npm link express
The terminal said that this command ran, but I still cannot run the express command.
Thanks for asking questions on this one. I found that running express-generator instead of just express fixed the problem. The following code in the terminal worked.
sudo npm install -g express-generator
Thanks again,
If your express binary keeps doing nothing. Install node-legacy:
sudo apt-get install nodejs-legacy
on ubuntu 14.04 nodejs 0.10 express did not work on terminal, though
sudo apt-get install nodejs-legacy
made it to work.
I faced similar issue. I tried all the solutions mentioned here. However couldn't get my problem solved.
This happens when location of express and nodejs is not same.
Issue arises when Node is installed using homebrew.
Just use this command export PATH=/usr/local/share/npm/bin:$PATH
NOTE: replace path with the path of express.
Follow this link for help.
Make sure you have package.json & index.js files. And instaled express-generator with -g tag.
If still getting error use like ex:npx express --view=pug myapp --git
I fixed this on my mac by forcing my user to own /usr/local/lib and running the command to install express-generator globally:
sudo chown -R $USER /usr/local/lib
then:
npm install -g express-generator
After this you can go ahead and run your express commands:
express -h

Resources