Install express-generator without global attribute - node.js

I am working on a VPS through Dreamhost and they do not allow the use of sudo so I can not install express-generator globally. I really like all the files that express initiates when calling the express command. Is there a way to install express-generator without the global attribute or a way to get all the files that the command express initializes?

Remember when you npm install x then there's always the option of running whatever it installed via node_modules/x/bin/x if that's the name of the shell command it installs.

Related

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

Node npm global install of express cloud9

I am trying to install express globally in cloud 9 IDE. I run the following command -
npm install -g express
then on the bash prompt I enter -
express --version
I get unknown command error?
Can I not install stuff globally on cloud 9 ?
Niladri
You need to add environment variables to achieve that in windows some times. May be you can try that there.

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

Error loading modules in nodejs, node and nom installed using repos Ubuntu

I have installed nodejs and npm using repos in Ubuntu 12.10, and generally I install a module using
sudo npm install -g nodemodule
but when I try to do var mod = require("nodemodule") I receive an error I have to use require("/usr/lib/node_modules/nodemodule"), how canI fix this?
You probably need to set the NODE_PATH environment variabele:
export NODE_PATH=/usr/lib/node_modules/:$NODE_PATH
After that, try your Node script again. If it works, place the line above in your shells' startup file (usually ~/.bashrc) so it will always be set when you log in.

'Express' is not recognized command (windows)

Okay I am running node on windows (7). Using npm I just installed modules to d:\ directory. Therefore my files structure looks like the following:
D:\
-myproject
-node_modules
-.bin
-express
However, when I am in this 'myproject' directory, I can't seem to run 'express' for example:
D:\myproject\express site
'express' is not recognized as an internal or external command, operable program or batch file.
Am I doing anything wrong?
Try:
npm install -g express-generator#3
That solved problem for me.
Edit: for version 4
npm install express-generator -g
Description:
express is the package for dependency of express js.
express-generator is the package for enabeling express command and create a sample project, etc.
Assuming that this is kept separate for the decoupling of project dependency with cli tool of express.
Another SO ref: https://stackoverflow.com/a/41311733/1666582
Here's what to type in the command line to make it work in windows:
npm install express-generator -g
[Source: http://expressjs.com/starter/generator.html]
My guess is that you didn't install Express globally. You can install express globally (and therefore available in your PATH) with the following command (see http://expressjs.com/guide.html) :
npm install -g express
The way you install it is available only in the folder that you installed it and there is nothing wrong with that approach. There is very little advantage of having it available globally.
If express is not in your PATH you can run it by entering the full path to it:
\myproject\node_modules\.bin\express.cmd
With the release of Express 4.0.0 it looks like you need to do
npm install -g express-generator
We need to set path for express global directory
C:\Users[User_Name]\AppData\Roaming\npm\
After add a new path, please reopen the CMD console
Tried all of these and never worked. A repair of Node.js by kicking of installation and selecting repair option does the magic.
Cheers
What worked for me was:
I used the windows command prompt instead of the node.js command prompt.
In windows 10 simply type in the windows search bar for "node"
You see a node.js desktop app and a node js command prompt.
Choose the "node js command prompt"
Type in the command prompt
npm install express-generator -g
Then navigate somewhere and type in:
express your-website-text-here -e
A directory with express files will be generated. Also now you won't see the express error.
I was able to fix with the following package install:
npm install express-generator -g
Thanks
When you install Node.js, the below path is added to the Windows OS %Path% variable, I'm presuming similar happens on other operating systems as well:
C:\Users\<your-windows-username>\AppData\Roaming\npm
In my case, because I use a work Windows laptop for an employer that severely restricts what employees can do on their machines (I.e. many actions require elevated admin privileges), Node.js was being prevented from adding the above path to the Windows %Path% environment variable, and much to my chagrin the Node.js installation was silent about it. Navigate to above folder and you will notice the express command lives there, see screenshot below.
How did I figure this out? I did a fresh installation of Node.js on a personal, home Windows machine that has no admin privilege restrictions like my work machine does, compared the before and after %Path% value, and noticed the addition of that path. My work machine was missing it.
I had no choice but to add the path manually to %Path%, and then express was recognized from within any path I ran it.
I was able to fix this with:
npm install express-generator -g
I tried all the above solution, no luck for me.
Open "Node.js" command prompt and tried as administrator. It is working fine for me. Don't try with windows command prompt.
I have the same problem and understand the solution, but i can´t undestand why, running npm install -g express, express.bat isn´t added automatically to Path.
Running with npm install -g express have the same result. Download packages and store in node_modules, but express.bat isn´t added to path.
Run the node command prompt as administrator and then install express globaly
npm install -g express
and then go to folder where you want to install express generator, open command prompt there and run this command
npm install express-generator, it will then fix the issue
I have tried out all above solutions, but its did't worked for me, finally I have re-installed the node.js with newer version and started to express install process again. Its worked for me.
npm install -g express
npm install -g express-generator
What command are you using to open the directory?
That error means CMD can't find the "express" executable in the current directory.
Use the "PUSHD" command or "CD /D" instead of "CD"
#Echo OFF
PUSHD "D:\myproject\express" || (Echo bad folder)
express.exe "site"
Pause&Exit
Express is loaded someplace else and not in the windows path environment variable. You need to find were express.exe is installed and add the path. Maybe something like ;"C:\Program Files\Express\bin";
Running "npm install express" and "npm install express-generator" from your project directory will resolve the issue (if that helps).
But, this doesn't solve the problem of being global.
You might check the permissions to the folder if you are getting this when creating your project
Express Project
change script section in package.json file like this
"scripts": {
"start": "node app.js"
}
I too faced the similar problem and at last I tried using node.js command prompt instead of windows command prompt and it worked. So, try from node.js command prompt.
Tried all of these but didn't work for me. Also, I tried from different sources but never worked for me.
In the end, found that I need to run the command forcefully. It worked for me.
Make sure you run the command with Run as Administrator.
npm install -g --force express-generator
It will overwrite the existing express files.
Use npm start .. then the app.js runs .. which can be listened on the usual port 3000

Resources