npm start run in wrong path - node.js

First of all i'm using Ubuntu 14.04, and i create a node.js project under /home/user/project_folder.
When i type npm start /home/user/project_folder/, i get this error:
npm ERR! node v4.6.1
npm ERR! npm v4.0.2
npm ERR! path /home/user/package.json
npm ERR! code ENOENT
npm ERR! errno -2
no such file or dir..
Am'i doing it wrong? did i forget something?
Thank you.

npm doesn't take the path as an argument.
What you want is:
cd /home/user/project_folder && npm start
You can put it in a script, e.g. save this as /home/user/project_folder/run.sh:
#!/bin/sh
cd /home/user/project_folder && npm start
Change permissions with:
chmod a+x /home/user/project_folder/run.sh
And run it with just:
/home/user/project_folder/run.sh
Or without changing permissions:
sh /home/user/project_folder/run.sh

When you use npm start you don't need to specify the file path. You have to be on the directory of your project cd project_directory and there run npm start. Also make sure that in your package json, you have specified in the "start" property, the file to start.

Related

bash: npm: command not found in cPanel Terminal

I get response, When try to write:
$ /opt/cpanel/ea-nodejs16/bin/npm -v
8.1.2
but with :
$ npm -v
bash: npm: command not found
So, I tried as the same logic but it didn't work:
$ /opt/cpanel/ea-nodejs16/bin/npm install
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/mydomain/public_html/app/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/mydomain/public_html/app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /home/mydomain/.npm/_logs/2022-03-02T14_43_55_155Z-debug.log
So, how to make " npm " command lines works on server.
First install NodeJS install on cPanel, WHM.
To install NodeJS from WHM, Goto Home /
Software /
EasyApache 4
And in Additional Packages find NodeJS.
After that create an environment variable which points to the node directory.
Run this command to do that.
export PATH=/opt/cpanel/ea-nodejs16/bin/:$PATH
Finally run npm -v to check NodeJS version.
Hope this will help for someone.
You need to create an environment variable which points to the right directory. This should do the job:
export PATH=/opt/cpanel/ea-nodejs16/bin/:$PATH
or add it to your .bashrc file to keep it persistent. And regarding this npm error you get, as jordanm mentioned you don't have package.json file in you current directory.
You have to store the path inside in your .bashrc file. You can do it easily by run following command.
echo export PATH=/opt/cpanel/ea-nodejs16/bin/:$PATH

i cannot install nodemon in npm nodejs

i can not install nodemon it has problem with npm
Vus-MacBook-Air:nodejs vuvantuu$ sudo npm install -g nodemon
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules/nodemon
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall access
npm ERR! enoent ENOENT: no such file or directory, access '/usr/local/lib/node_modules/nodemon'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/vuvantuu/.npm/_logs/2019-08-08T07_07_43_043Z-debug.log
You must be required administrative privileges to install anything,
you can use
sudo npm install -g nodemon
As the error says - you don't have write access to the /usr/local/lib/node_modules folder.
The simplest way to get rid of this error - is to run the command via sudo
sudo npm i -g nodemon
But if you don't want to run it via root user for any reasons (e.g security) you could install packages globally for a given user.
Create a directory for global packages
mkdir "${HOME}/.npm-packages"
Tell npm where to store globally installed packages
npm config set prefix "${HOME}/.npm-packages"
Ensure npm will find installed binaries and man pages
Add the following to your .bashrc/.zshrc:
NPM_PACKAGES="${HOME}/.npm-packages"
export PATH="$NPM_PACKAGES/bin:$PATH"
# Unset manpath so we can inherit from /etc/manpath via the `manpath` command
unset MANPATH # delete if you already modified MANPATH elsewhere in your config
export MANPATH="$NPM_PACKAGES/share/man:$(manpath)"
NOTE: If you are running macOS, the .bashrc file may not yet exist, and the terminal will be obtaining its environment parameters from another file, such as .profile or .bash_profile. These files also reside in the user's home folder. In this case, simply adding the following line to them will instruct Terminal to also load the .bashrc file:
source ~/.bashrc

in electron.js npm start command not working.its saying electron is not recognise as internal or external command

operable program or batch file.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! electron#1.0.0 start: `electron .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the electron#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
It seems that electron is not installed yet. In order to run the electron command you need to have node and npm installed and configured correctly then run.
npm i -g electron
i tried almost everything but finally i able to solved it .
"electron-webpack-quick-start" setup everything for us we don't need to worry about installation of pacakges just run the command and have fun
it worked for me.
mkdir new-electron-webpack-project
cd new-electron-webpack-project
3.curl -fsSL https://github.com/electron-userland/electron-webpack-quick-start/archive/master.tar.gz | tar -xz --strip-components 1
git clone https://github.com/electron-userland/electron-webpack-quick-start.git
5.cd electron-webpack-quick-start
rm -rf .git
yarn
8.yarn dev
for more info read link below
https://github.com/electron-userland/electron-webpack-quick-start

npm start does not work

npm start
npm ERR! path C:\WINDOWS\System32\WindowsPowerShell\v1.0\package.json
npm ERR! code ENOENT
npm ERR! errno -4058
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open 'C:\WINDOWS\System32\WindowsPowerShell\v1.0\package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\ATUL\AppData\Roaming\npm-cache\_logs\2017-10-01T10_20_21_068Z-debug.log
I am following the Wes-bos tutorial of learn-node. When I do npm start, it gives me these errors. Please help me. I have referred to all the previous questions. I am not able to find anything.
You have to run npm start in the root of the project you want to run, it seems you are runing npm start in a folder where there is not a package.json file.
The error says that you are running npm start in this path C:\WINDOWS\System32\WindowsPowerShell\v1.0\package.json but it seems that inside that folder you don't have a package.json file, so maybe you are in a wrong folder location.
So, if you downloaded some code to get started with, you should move to the root of that code and then run npm start.
If you are starting a new app, you have to run npm init first, that command will create a package.json file in the same location where you are in the console and then you will be able to run npm start.
I just had the same problem, so far I have never seen it.
But my solution was:
Rename the project folder (remove [], (), {} and special characters). Also try to remove spaces between words and if you continue the error try to join or just use (- or _) instead of space
Keep an eye on which folder is being performed. "When I didn't run: npm init -y" he would throw me to (C: \ WINDOWS \ System32 \ WindowsPowerShell \ v1.0 \ package.json), you don't want to run here,
use your project folder, change in the terminal to your folder: cd './c:\user\...\project'
Note: Solution tested in Windows - Visual Studio Code v1.56.0
nodejs vs-code visual-studio-code npm

Error: EACCES, permission denied even after using sudo?

I am trying to set up a chrome extension that will automatically save the changes I make to my website with the inspect element feature. The idea is that you'll be able to make real time changes to the website without having to go back into the ide to save the changes and re-upload and everything. The extension is called DevTools Autosave. I've been following the instructions from this site. I'm trying to install this on a mac.
I've installed node.js and the extension already. When I got to the part in the instructions where it talks about which commands to run in the terminal I've tried both with and without the "sudo" in front of the "npm install -g autosave" command but I always get this error:
Error: EACCES, permission denied
at Function.startup.resolveArgv0 (node.js:815:23)
at startup (node.js:58:13)
at node.js:906:3
npm ERR! autosave#1.0.3 install: `node ./scripts/install.js`
npm ERR! Exit status 8
npm ERR!
npm ERR! Failed at the autosave#1.0.3 install script.
npm ERR! This is most likely a problem with the autosave package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node ./scripts/install.js
npm ERR! You can get their info via:
npm ERR! npm owner ls autosave
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 14.0.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "autosave"
npm ERR! cwd /Users/Brent
npm ERR! node -v v0.10.33
npm ERR! npm -v 1.4.28
npm ERR! code ELIFECYCLE
npm ERR! not ok code 0
Anyone know how I can fix this? I can't find anyone that is having this problem and I've been on a few different forums now but can't find a solution. Thanks in advance.
You have two options: Either fix your npm setup, so you can use npm -g, or install autosave locally.
To install locally (i.e. in node_modules within your current directory), run npm install autosave (without -g). Then you can run ./node_modules/.bin/autosave or ./node_modules/autosave/bin/autosave to start autosave.
To fix your npm setup, so you can use -g without root permissions (recommended):
In your home dir (assuming /Users/Brent/), create a file called .npmrc with the following content:
cache = /Users/Brent/.npm/cache
globalconfig = /Users/Brent/.npm/npmrc
globalignorefile = /Users/Brent/.npm/npmignore
prefix = /Users/Brent/.npm
And add ~/.npm/lib/node_modules to your NODE_PATH, e.g. by putting the following in .bashrc (assuming that your shell is bash) to allow the modules to be found, and append ~/.npm/bintoPATHso you can run any installed binary (i.e. runautosave` from anywhere):
export NODE_PATH=$HOME/.npm/lib/node_modules
export PATH=$PATH:$HOME/.npm/bin
(changes to .bashrc only take effect when you load the shell, or use . ~/.bashrc; if you want to use the new setup without reloading the shell, just run that line (export ...) in your current shell).
As of 2020, here is the recommended solution by npm. It worked for me (OSX). (No need to change any path configuration or .bashrc)
Steps:
Install nvm by running below command.
If you are using bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | bash
If you are using zsh
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.2/install.sh | zsh
Install node using nvm (No need to uninstall existing node/npm)
nvm install 12.13.1

Resources