cannot install npm? problems generating application - javascript

ok ... first time I'm trying my hand at node.js.
installed it a while back, and not sure how i installed it.
last night, decided to tackle a tutorial regarding node.js and express.
checked my version of node which is v0.8.14 and npm which is 1.1.65. (I'm on Mac, 10.6.8 version)
but did this anyway
npm install -g express
seemed to go ok ... but whenever I tried to generate a new application via
express new ProjectName
I got this:
-bash: express: command not found
Decided to try
sudo npm install express -g
which again seemed to go well ... but again, the express new ProjectName got the same statement.
tried again:
npm install -g express
got a lot of errors unlike the first time.
npm WARN package.json application-name#0.0.1 No README.md file found!
AA-s-MacBook-Pro:express_node aa$ express new HotPie
-bash: express: command not found
AA-s-MacBook-Pro:express_node aa$ npm cache clean
AA-s-MacBook-Pro:express_node aa$ npm install -g express
npm http GET https://registry.npmjs.org/express
npm http 200 https://registry.npmjs.org/express
npm http GET https://registry.npmjs.org/express/-/express-3.0.6.tgz
npm http 200 https://registry.npmjs.org/express/-/express-3.0.6.tgz
npm ERR! error rolling back Error: EPERM, chmod '/usr/local/share/npm/bin/express'
npm ERR! error rolling back express#3.0.6 { [Error: EPERM, chmod '/usr/local/share /npm/bin/express']
npm ERR! error rolling back errno: 50,
npm ERR! error rolling back code: 'EPERM',
npm ERR! error rolling back path: '/usr/local/share/npm/bin/express' }
npm ERR! Error: EPERM, chmod '/usr/local/share/npm/bin/express'
npm ERR! { [Error: EPERM, chmod '/usr/local/share/npm/bin/express']
npm ERR! errno: 50,
npm ERR! code: 'EPERM',
npm ERR! path: '/usr/local/share/npm/bin/express' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 10.8.0
npm ERR! command "/usr/local/Cellar/node/0.8.14/bin/node" "/usr/local/bin/npm" "install" "-g" "express"
npm ERR! cwd /Users/aa/Documents/express_node
npm ERR! node -v v0.8.14
npm ERR! npm -v 1.1.65
npm ERR! path /usr/local/share/npm/bin/express
npm ERR! code EPERM
npm ERR! errno 50
npm ERR! stack Error: EPERM, chmod '/usr/local/share/npm/bin/express'
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/aa/Documents/express_node/npm-debug.log
npm ERR! not ok code 0
and so it went on and on: errors ... or no errors. I'm at total loss. and online literature on fixing this problem seems rather sparse.
advice, please?
oh, also saw this somewhere online: (whatever it means)
/usr/local/share/npm/bin/express
which resulted in this:
destination is not empty, continue?
destination is not empty, continue? (yes or no) yes
create : .
create : ./package.json
create : ./app.js
create : ./public/javascripts
create : ./public/images
create : ./public/stylesheets
create : ./public/stylesheets/style.css
create : ./routes
create : ./routes/index.js
create : ./routes/user.js
create : ./views
create : ./views/layout.jade
create : ./views/index.jade
create : ./public
install dependencies:
$ cd . && npm install
run the app:
$ node app
so ... ??? any advice would be appreciated! (please also let me know if I left any pertinent information required)

Sounds like you need to edit your path variable.
Edit your ~/.bash_profile. Add this export somewhere.
export PATH=/usr/local/bin:$PATH:/usr/local/share/npm/bin
What's happening is that node isn't setting up its PATH correctly. I've had this happen to me before. Its something they should fix.
You may not have a .bash_profile. In *nix systems, there are a few different files you can place in your home directory to add environment variables and such.
bash_profile is the one I prefer, so in the terminal cd to ~ and touch .bash_profile.
Then edit it via nano .bash_profile or whatever editor you like.
(In nano, control-o to save, control-x to exit.)
When you've added it, do: source .bash_profile
Then try which express and see if it shows the path.

Related

Error in installing 'nodemon' using 'npm'

I recently started working with 'npm' and while installing 'nodemon' using command -
npm i -g nodemon
but it is showing ERR!
npm ERR! code EACCES
npm ERR! syscall rename
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! dest /usr/local/lib/node_modules/.nodemon-SfftGed4
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/nodemon' -> '/usr/local/lib/node_modules/.nodemon-SfftGed4'
npm ERR! [Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/nodemon' -> '/usr/local/lib/node_modules/.nodemon-SfftGed4'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'rename',
npm ERR! path: '/usr/local/lib/node_modules/nodemon',
npm ERR! dest: '/usr/local/lib/node_modules/.nodemon-SfftGed4'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rishabhsingh/.npm/_logs/2023-01-28T12_41_30_475Z-debug-0.log
I tried using sudo to install nodemon, clearing cache using npm cache clear even with --force but no help, also tried what terminal was showing me could be the erroe but turned out nothing helpful.
Be careful with this stuff!!
Don't arbitrarily run sudo commands. Some answers online will tell you to run chmod or chown in your /usr directory. This is not a good solution and may potentially break your whole system!
The problem is that npm is trying to install global packages in your /usr folder, but your user doesn't have access to this folder. What you need to do is tell npm to install global packages in a folder which you do have access to.
Create a directory for global npm packages:
mkdir "${HOME}/.npm-packages"
Tell npm where to store globally installed packagesL
npm config set prefix "${HOME}/.npm-packages"
Ensure npm will find the location by adding it to your system's PATH variable. This can be done by editing .bashrc or .zshrc in your home directory and adding the following code to the bottom of the file.
NPM_PACKAGES="${HOME}/.npm-packages"
export PATH="$PATH:$NPM_PACKAGES/bin"
# Preserve MANPATH if you already defined it somewhere in your config.
# Otherwise, fall back to `manpath` so we can inherit from `/etc/manpath`.
export MANPATH="${MANPATH-$(manpath)}:$NPM_PACKAGES/share/man"
Close and re-open your terminal.

Can´t start the server created from the express.js generator

I am trying to setup a express.js server using there generator. I have followed the documation and I have succesfully created the basic structure. However if I try to run the given command (SET DEBUG=transcriptverificationserver:* & npm start) to start the server I always get the following error:
npm ERR! Missing script: "start"
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! npm stars # View packages marked as favorites
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\a\AppData\Local\npm-cache\_logs\2022-11-28T22_43_43_285Z-debug-0.log
PS C:\Users\a\Desktop\Verified Transcripts\Webpage> npm start
npm ERR! Missing script: "start"
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! npm star # Mark your favorite packages
npm ERR! npm stars # View packages marked as favorites
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\a\AppData\Local\npm-cache\_logs\2022-11-28T22_45_41_209Z-debug-0.log
I assume its an issue within the package.json file. The script part looks as following:
"scripts": {
"start": "node ./bin/www"
},
I haven´t change anything in the files or structure and I was simply copying the commands from the documentation (https://expressjs.com/en/starter/generator.html)
Thanks for any help in advance
I have tried it again and this time everthing works. I am not sure what has happend before but I might have used the old installation method.
$ npm install -g express-generator
$ express
With my secound try I ensured to use the new method:
$ npx express-generator

npm install error/issue

I have already set proxy configurations in .npmrc file.
Executing the npm install command gives me error as follows"
$ npm install npm ERR! Windows_NT 6.1.7601 npm ERR! argv "C:\Program
Files\nodejs\node.exe" "C:\Program
Files\nodejs\node_modules\npm\bin\npm-cli.js" "install" npm ERR!
node v6.9.4 npm ERR! npm v3.10.10 npm ERR! code ECONNRESET
npm ERR! network tunneling socket could not be established,
statusCode=400 npm ERR! network This is most likely not a problem with
npm itself npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad
network settings. npm ERR! network npm ERR! network If you are behind
a proxy, please make sure that the npm ERR! network 'proxy' config is
set properly. See: 'npm help config'
npm ERR! Please include the following file with any support request:
npm ERR! D:\Pooja\quickstart\npm-debug.log
The .npmrc file in user folder contains following values
1. registry=https://registry.npmjs.org/
2. proxy=http://proxy#domain.com:8080/
3. http_proxy=http://username:password#proxy#domain.com:8080/
Is there any way to solve this issue?
Does your proxy URL have '#' symbol in it? # symbol separates the user ID and password from the URL. If it does, you can try using '%40' to replace it.
Also, it is https-proxy not http_proxy.
A correct config would look like -
registry=https://registry.npmjs.org/
proxy=http://username:password#proxydomain:8080/
https-proxy=https://username:password#proxydomain:8080/
https://docs.npmjs.com/misc/config#proxy
first give the command
and check if proxy is set,npm config get proxy if not set do the following from command prompt
npm config set proxy http://username:password#proxy address:8080
npm config set https-proxy http://username:password#proxy address:8080
and if password contains '#'in password, then replace it with '%40'
Someone who comes from china may solve this problem by using Taobao mirror.
npm --registry=https://registry.npm.taobao.org install

NodeJS - setting up mean.io cannot find module errors

I'm sort of new to this whole "node" js thing. When trying to install the MEAN package from http://mean.io/, I followed these steps faithfully:
I "cd" to my directory, run "npm install", and then the "grunt" command, and get this error:
Error: Cannot find module 'coffee-script'
So I roll with the punches. npm install coffee-script, run "grunt" again.
Error: Cannot find module 'getobject'
Ever patient, I decide "okay, forget grunt". I run "node server". Then I get this error:
Error: Cannot find module 'merge-descriptors'
What's wrong? How can I get MEAN working here? (I thought npm was supposed to make life easier).
Update 12/31/13: When I look at the output of npm install, there are a number of "Error: EMFILE" errors. As I understand those errors are related to too many files being opened and graceful-fs is a solution to this. Sample EMFILE error pasted below:
npm ERR! System Darwin 13.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/cnokes/Desktop/mean-master
npm ERR! node -v v0.10.7
npm ERR! npm -v 1.2.21
npm ERR! path /Users/cnokes/Desktop/mean-master/node_modules/grunt/node_modules/iconv-lite/README.md
npm ERR! code EMFILE
npm ERR! errno 20
npm ERR! tar.unpack error reading /var/folders/wv/xrm8qphn5bsgfj5w45kqrwl9lgq2j2/T/npm-27019/1388513549132-0.22752901865169406/tmp.tgz
With graceful-fs installed, I re-run npm install and get a couple of these errors:
npm ERR! Error: ENOENT, utime '/Users/cnokes/Downloads/mean-master2/node_modules/express/node_modules/fresh/index.js'
I've run in to this and think this might be connected to another issue.
Basically it's related to the number of open files (alot) that get open when we do a npm install.
It has been blogged about nicely here - http://otaqui.com/blog/1618/how-to-fix-error-emfile-too-many-open-files-from-yeoman-and-npm/
and I update the mean FAQ
https://github.com/linnovate/mean/wiki/Faq

Error trying to install npm for Node.js

I'm having a stab at learning Node.js and I'm having a few issues when installing NPM (Node Package Manager). I'm pretty sure it's either a permissions thing or folder thing... please note that I've just purchased a Mac (I've used Windows all my life) and I'm pretty unfamiliar with the Mac terminal.
Okay, I went to use the one line install for NPM: curl http://npmjs.org/install.sh | sh and I got an error...
All clean!
! [ -d .git ] || git submodule update --init --recursive
node cli.js rm npm -g -f
node cli.js install -g -f
npm ERR! Could not create /usr/local/lib/node_modules/___npm.npm
npm ERR! error installing npm#1.0.94 Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR!
npm ERR! System Darwin 11.0.0
npm ERR! command "node" "/private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/cli.js" "install" "-g" "-f"
npm ERR! cwd /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package
npm ERR! node -v v0.5.9-pre
npm ERR! npm -v 1.0.94
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCESS
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/npm-debug.log
npm not ok
make: *** [install] Error 1
npm ERR! Could not create /usr/local/lib/node_modules/___npm.npm
npm ERR! error installing npm#1.0.94 Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Error: EACCESS, Undefined error: 0 '/usr/local/lib/node_modules'
npm ERR! Report this *entire* log at:
npm ERR! <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR! <npm-#googlegroups.com>
npm ERR!
npm ERR! System Darwin 11.0.0
npm ERR! command "/usr/local/bin/node" "/private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/cli.js" "install" "-gf"
npm ERR! cwd /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package
npm ERR! node -v v0.5.9-pre
npm ERR! npm -v 1.0.94
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCESS
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /private/var/folders/z2/f05c8hx105g79drh6r7hr01w0000gn/T/npm.1219/package/npm-debug.log
npm not ok
It failed
there's obviously a folder issue here, perhaps I'm installing in the wrong place, my node folder is at Users/Mike/node, when I try and find out my node path variable using NODE_PATH I get the following error:
Michaels-MacBook-Pro:~ Mike$ node node/NODE_PATH
node.js:203
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module '/Users/Mike/node/NODE_PATH'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Array.<anonymous> (module.js:470:10)
at EventEmitter._tickCallback (node.js:195:26)
Can someone please tell me what I'm doing wrong? Do I need to add the node path like such:
$ export PATH=/path/to/node/0.n.y/bin:${PATH}
$ curl http://npmjs.org/install.sh | sh
Or am I confusing myself?
The permissions on /usr/local require you to use sudo to install NPM, or change your permissions. Of these three, I recommend the third option.
Option #1: Use sudo
(Note that the the creator of NPM advises against using this method)
curl http://npmjs.org/install.sh | sudo sh
Option #2: Change permissions
sudo chmod g+rwx /usr/local
sudo chgrp admin /usr/local
Option #3: Use Homebrew
I recommend installing Homebrew to manage installing *nix tools on OS X (I'd stay away from MacPorts & Fink). Installing Homebrew will set the permissions for /usr/local so you can write to it without sudo. You can then install Node via Homebrew, and then install NPM normally:
brew install node --without-npm
curl http://npmjs.org/install.sh | sh
Use curl http://npmjs.org/install.sh | sudo sh.
Edit: You're using node -v v0.5.9-pre, which is very unstable. Use 0.4.12, the latest stable version.
if you are using windows , it takes some steps , 1) create a file called package.json
{
"name": "hello"
, "version": "0.0.1"
, "dependencies": {
"express": "*"
}
}
where hello is the name of the package and * means the latest version of your dependency
2) code to you project directory and run the following command
npm install
As update for the method #3 on OSX the correct command now is:
brew install node --without-npm
curl https://www.npmjs.org/install.sh | sh
Option #4:
Install node local to the user that needs it.
I should clarify for my purposes I needed npm to install appium on an OSX server running Bamboo for our integrated testing. I only had macports available and rather than installing homebrew to manage just the one package I decided to build it from source and install it local to the bamboo user. Which allowed us to run appium as the bamboo user and made it possible to run our appium tests on Bamboo as a not very privileged user.
This guide from Tom Novelli goes over how to do it. The basic gist is:
# Make the dir to hold the installation of node
cd
mkdir ./local
mkdir sources
# Tell npm about your new non-default directories
vi .npmrc
cd sources
# Get node and do the typical source install procedure
wget http://nodejs.org/dist/v0.10.29/node-v0.10.29.tar.gz
tar xf node-v0.10.29.tar.gz
cd node-v8.10.29/
# Important part is the --prefix
./configure --prefix=~/.local
make
make install
# Make a link so node doesn't get confused
cd
ln -s .local/lib/node_modules .node_modules
# Edit PATH to include ~/.local
vi .bashrc
.npmrc
root = /home/YOUR-USERNAME/.local/lib/node_modules
binroot = /home/YOUR-USERNAME/.local/bin
manroot = /home/YOUR-USERNAME/.local/share/man
.bashrc OR .profile OR whereever you like setting your path
export PATH=$HOME/.local/bin:$PATH
Useful Links
The .npmrc man page useful.
And just in case here's a link to node source.

Categories