Not Getting $ in command prompt in Node.Js - javascript

My NodeJs is working fine but i have an issue I'm not seeing $ in the prompt as most example point.
Another issue is when i put sudo I dont get anything.Things I have tried are the following
$ sudo npm install npm -g
/usr/bin/npm -> /usr/lib/node_modules/npm/bin/npm-cli.js
npm#2.7.1 /usr/lib/node_modules/npm
given on the following Website
http://www.tutorialspoint.com/nodejs/nodejs_npm.htm
Apologies am very new to Node.JS.Please help

I'm going to explain this in terms familiar to MS windows.
$ npm --version
^ dollar sign is the same as "C:\" in windows.
It just means "from here..." in the most basic terms I can use.
You don't need the dollar sign for anything in that tutorial.
"sudo" means "elevate to an administrator level" similar to opening a command line terminal "in administrator mode." But for Linux (Ubuntu and Mac as *NIX) systems.
--version can be called as "-v" most of the time and means "for the thing I've named before, in this case "npm" show me the version.
Once you've installed NodeJS it comes with a "package manager" called NPM. The best way to relate this to windows is by considering it a command line version of an "installation" that installs different programs as you tell it to with different options.
"npm install -g" means "Hey NPM! Install to EVERYWHERE(call from command line/terminal/bash) the thing I Tell you next. "npm install -g express" for example, means hey NPM, install "expressJS" globally, so I can use the terminal to write commands(micro apps) from the expressJS I just installed with node.
"npm install --save" means hey, install this microapp, but ONLY let me use it in THIS EXACT FOLDER I'm in, and let anyone else that is in this folder know they need to install it to use this application I'm making.
"npm init" Is actually the FIRST thing you should do in any node project folder. It creates the "package.json" file in the current directory, and it will define the folder you're in as the folder to start installing stuff you "npm install" to the "node_modules" folder that will show in the folder you're currently in.
If you want to tinker with NodeJS code, and you don't want to tamper with your local machine and install all kinds of stuff you're not totally sure about yet you can use "REPL.it" (https://repl.it/languages/nodejs) the white window on the right is treated like a file you'd run in node. The dark window on the right is an actual NODE TERMINAL that you can run nodejs commands/code in directly.
There's one other good resources in general and that is here (https://devdocs.io/) it's called "Devdocs" and it has Node, npm, and express code examples, clean explanations, and examples that you can download directly to your local machine.
I hope that gets you moving with NodeJS. It's hard to understand, but with a bit of try and fail you'll start to try more and fail less. Cheers!

Related

'firebase' is not recognized as an internal or external command, operable program or batch file

I am in a bizarre problem, I just updated my Node.js and NPM at the date of 01-Feb-2019. And used the following command-
npm install -g firebase-tools
to install the Firebase CLI
Then on typing either of the code below
firebase login
or
firebase init
it is showing the following error
'firebase' is not recognized as an internal or external command,
operable program or batch file.
Please help me. It has already consumed my two days.
npm install -g firebase-tools -f
Using -f for force install again.
This work for me
Ok. First of all, Bizarre problem has some bizarre solution.
Uninstall your node js and NPM completely.
Then reinstall it, and check, whether it works or not.
Best of Luck
If you are using MS Windows:
Open Start Menu or press Win button on your keyboard.
Type "variables".
Click on "Edit the system environment variables"
Click on "Environment Variables..." button.
In the "System variables" list select "Path" and click on the "Edit..." button under the list.
In the "Edit environment variable" dialog click on the "Browse..." button.
Navigate to the c:\users\<yourusername>\AppData\Roaming\ dir and select the "npm" sub-dir, then click "OK".
In the "Edit environment variable" dialog click "OK".
In the "Environment Variables" dialog click on "OK".
For the Linux users:
Navigate to the home_dir.
Edit the hidden ".bash_profile" file.
Add line with following text "export PATH="$PATH:/usr/local/bin".
add to .bash_profile
export PATH="$PATH:/usr/local/bin"
and run
npm install -g firebase-tools
this worked for me
Navigate to the firebase directory and call it out on the cmd.
run cmd as admin
cd C:\users\yourusername\AppData\Roaming\npm
firebase.cmd login or firebase login
firebase will prompt a google login after which the issue should be resolved.
There you go. above steps are all commands goes to your command prompt.
After running npm install -g firebase-tools, go to C:\usr\local. You will see Firebase files.
Copy this path C:\usr\local to the clipboard.
Open the Start Menu and search for Edit the System Environment Variables or simply env.
Select the environment variables option that appears.
Find the PATH variable under the system environment variables (lower section).
Select PATH and click Edit
Add C:\user\local to the beginning of the path.
Add %APPDATA%\npm if it doesn't exist.
Click OK to each of the windows until they're all closed.
After this, open a Windows command prompt and run firebase --version.
My solution is to use Firebase CLI binary for Windows:
Download CLI: https://firebase.google.com/docs/cli#install-cli-windows
Run CLI, go to the project directory (cd 'your app path'). By the way, you may see the version: run "firebase --version" for that
Run "firebase login" with Firebase CLI
Run "firebase init" with Firebase CLI
Make sure you are running command line as an administer.
Make sure you run the CMD in administrator mode. Also once you have run
npm install -g firebase-tools commands close the CMD prompt and reopen again. If this doesn't work uninstall node and reinstall it again. It requires your node version to be a minimum version to support firebase.
After installing
$ npm install -g firebase-tools
Note the directory where it installed
What I did was locate the directory where firebase was installed. In my case C:\usr\local then I copied the three firebase files. I also went into the node_modules folder and copied the firebase tools folder. Then I went to my app directory in file manager and pasted the firebase files, then created a new node_modules folder and pasted the firebase-tools folder.
Now go to your cmd and run
$ firebase init
It should work
1.After installing firebase globally via npm i -g firebase-tools
2.simply run all your firebase commands from the node command-line tool, it instantly worked for me.
3.To access the node command line, simply go to the start menu on windows and type "node.js command prompt"
Add this to the environment variable:-
C:\Users\<user>\AppData\Roaming\npm\firebase
it will allow firebase commands in ps/cmd
i dont think : C:\Users<user>\AppData\Roaming\npm\ now works.
I was struggling with this same issue for a few days and had an issue where my NPM was installed in two different places for whatever reason.
I had an npm folder in C:\Users\<user>\AppData\Roaming\npm\ as well as C:\Users\<user>\npm\
Turns out the Firebase installation command installed all the needed files into the latter folder, while my Environment PATH was pointing to the first folder.
I changed my PATH variable to C:\Users\<user>\npm\ and ran the firebase installation again. After that everything started working fine.
If you havent checked the other answers about what PATH is, you can access it by typing env in the Windows search bar and from there click the Environment Variables button. Then double click the Path line under System variables to edit it. Remember to press OK to save any changes.
This is probably a rare edgecase, but maybe it will help someone.
For peeps like me who were unable to get rid of this problem after trying everything suggested above.
I know it is late but I Fixed it by changing the location for installing my packages.
I ran the command "npm config get prefix" in cmd and I found out that my default location for node_modules installation had been changed.
so I set it back to default by "npm config set prefix "C:\Users\your_PC_Name\AppData\Roaming\npm".
After that I used "npm install -g firebase-tools" again
My firebase package was installed. I was relieved to see firebase.cmd file in npm folder.
Earlier I had tried every thing like uninstalling node.js and deleting npm and npm cache folders but all those methods didn't work for me.
Cannot get "npm install -g" to work on any packages (AppData/Roaming/npm always empty)
this discussion worked for me only.
all of the Simple and Quick solution is here... step1): just go to C:\Users\your-user-name\AppData\Roaming\npm step2): copy the path of this "npm"-folder step3): now go to start and type "env" and select first-option then step4): now paste that path in "paths"-option by clicking on "edit"-button step5): then click on "ok" and restart your pc
I had similar issue in MAC. Terminal was giving me command not found message on running "firebase --version". So, I tried to reinstall the firebase with the command: "sudo npm i g firebase-tools" but it again errored out stating that the installed firebase binary file is corrupted.
Solution:
STEP 1. Provide read, write and execute access with "sudo chmod a+rwx configstore" cmd to the path :
"/Users//.config/configstore/"
STEP 2. Run following command to update firebase:
sudo curl -sL firebase.tools | upgrade=true bash
Add C:\users\yourusername\AppData\Roaming\npm to your environment variable PATH.
For anyone still fighting this problem try to add the system environment path not to
a user's environment.
https://github.com/firebase/firebase-tools/issues/46#issuecomment-615534999
Run your cmd from C:\Windows\System32\cmd.exe or type this in your file path and hit Enter
Just reinstall firebas-tools {npm i firebase-tools -g} globally
Restart your computer its work for me good luck
Simple answer to this question is-
1.npm install firebase command in terminal window.
2.Add firebase scripts in your editor that you use.
3.set the Path in the environment system variable.
I think it will be able solve your problem...
My solution was that my project was on partition F: somedirectory/app, and when I moved it on partition C: Users/username/Documents/app It worked!
I tried everything mentioned and more, lost couple of hours.
So moving on partition where I installed: npm install -g firebase-tools
then: firebase login, then: firebase init
npx firebase <your command>
If you have similar problems like this
firebase : File C:\Users\<user-name>\AppData\Roaming\npm\firebase.ps1 cannot be loaded because running scripts is disabled on this system. For more em. For more
information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ firebase login
+ ~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
perhaps you can try to Ctrl + Click the C:\Users<user-name>\AppData\Roaming\npm\firebase.ps1
After that you'll see a new PowerShell Terminal and you can continue it.
Hope it's works

NPM Install giving rollbackFailedOptional

After trying to use the Windows Powershell (as an admin), the command prompt (as an admin) and the bash CMD; I repeatedly get the following error after trying an npm install command:
npm install npm#latest -g
is the attempted command and...
[...] / rollbackFailedOptional: verb npm-session xxxxxxxxxxx
where the 'x's represent different letter and number combinations at each attempt, is the message. I am aware that this should be the first step in the installation of a package but it remains on this message for a long time and will not change.
I am trying to use the JavaScript React library, more specifically the 'create-react-app'. The npm install -g create-react-app command is also causing the error.
npm version: 6.5.0
npx version: 10.2.0
node version: 10.15.0
A solution would be greatly appreciated.
https://docs.npmjs.com/try-the-latest-stable-version-of-npm In this link there is the documentation for updating npm version for windows with a link to a tool developed by Microsoft to update npm (https://github.com/felixrieseberg/npm-windows-upgrade)
I found the solution:
As my device username has both my first and last names, with a space in between, npm was reaching errors because of this. So the solution was to uninstall node from the default location and reinstall it in a folder on my C:\ drive, where there were no files in the directory that have spaces in the names. I then changed the cache location into this same C:\ drive folder, and the problem was solved.
npm config set cache C:\NODEJS\npm-cache
(these folders must be created before you can set the config directory to these.)
For me, I ended up having to:
Uninstall Node.js
Remove the folder "nodejs" completely from C:\Program Files (or
wherever you decided to install node)
Reinstall Node.js
After that, I did not encounter [...] / rollbackFailedOptional: verb npm-session xxxxxxxxxxx anymore.
I'm not quite sure what the issue was but all suggestions I found on stack did not solve this problem for me. I hope this helps someone.
Check if you are connected to any other VPN or proxy setting. If so try to disable it or disconnect from it and then execute the npm command. It worked for me. In my case, I was using the organization laptop and was connected to external vpn network, so i disabled the vpn and tried the command and it worked.
In our case the hard disc of the nexus server (repository server) was just full. Maybe someone helps this. Before looking into other more complicated options.
for my case i uninstalled the reinstelled it and used powershell insted of cmd and it worked like a charm
First run these commands.
npm config rm proxy
npm config rm https-proxy
then run this.
npm config set registry https://registry.npmjs.org/
check if the internet is connected
and try to run the npm command which was giving the error.

How to install Node.js or npm on Xampp

I'm new, so please excuse any mistakes.
I am trying to develop a web application locally using XAMPP. I intend to deploy using a hosted web service. XAMPP was a very convenient way to get me up and programming without any fuss.
There are several github javascript libraries that look like they can only be installed with npm. Does this mean that I cannot use them? The specific one that I'm currently having a problem with is: https://github.com/selz/plyr. Or, is it possible to install npm on my XAMPP server? I have a windows machine.
Thank you very much in advance for your help.
is it possible to install npm on my XAMPP server
You will not be installing NPM on your server, you will be installing it on your machine (think of it as a regular program you install on your PC) (if your server happens to be your PC as well, then, well, you are technically installing it on your server)
In order to be able to use NPM though, since NPM is written in JavaScript, you will need to install Node.js, also on your machine.
So, head over to the Node.js site and download and install Node. NPM is included in the installer and will be installed alongside Node.
After that is done, installing NPM packages is simply a matter of heading to your desired directory and executing npm install <PACKAGE_NAME> there.
In general, XAMPP helps you with your back end. Not your front end.
Useful links:
https://docs.npmjs.com/
Does this mean that I cannot use them?
No. You can install node at https://nodejs.org and then use npm through your windows command line to install packages. To test this, just
Install NodeJS
Open Command Line
Make a new folder under your user folder called test mkdir test
cd into that folder on Windows Command Line cd test
Create a new project with npm init -y *note this creates a
package.json file for you
Now you start installing packages with npm install <package>
--save * --save saves the package info in your package.json file (recommended). There is also -g wihch means the package will
be installed globally (usually you don't want this and only want it
locally to your project).
That's how you use NodeJS. If you want to use that with XAMPP then you need to do the same thing but instead of using your user folder (C:\users\yourname) you need to use the htdocs folder of XAMPP (usually C:\xampp\htdocs)

How to run a Node.JS app that is forked from github?

Before I say anything else, I am a complete noob to node.js and I just want to see what this web application looks like. I noticed this project at a hackathon and I wanted to test it out. They gave the github repo: https://github.com/android-fanatic/Web But I can't run it from my computer. I understand that I would need to use the command prompt and run it from my local server, but can someone give me step by step directions for installing the node.js app?
Again the link is:
https://github.com/android-fanatic/Web
Thanks in advance for any help! :)
Install Node.js
Clone the repository to somewhere on your hard drive
Open a command prompt and go to that directory
Type npm install to install any dependencies
Type npm start
???
PROFIT
The reason you can use npm start is because if you look inside of their package.json file you'll see a "start" option under "scripts". That command will execute when you type npm start.
Assuming you have node and npm installed on your system, you should be able to do:
npm install
npm start
The first command will install the node package dependencies and the second will run the server.
Note: I have never used this project, so my guess is based on looking at the repo alone.
The web application should be available at:
http://localhost:3000

Grunt.js Installation Issue - Command Not Found

I'm trying to get grunt.js set up on my work machine. Now I've managed to get it set up at home, so I pushed my repository, then cloned it on my work machine, however despite troubleshooting this to death I've always run into the same issue when I come to try and run the command on my work computer;
sh.exe": grunt: command not found
So some background and explanation;
I'm using Aptana 3.0 and running all my commands through the terminal. (This applies to my home and work computer)
I cloned the "working" repository and put it in a folder on my work machine, so I have my package.json and gruntfile.js files inside said directory. These work fine on my home computer and I am able to run the watch task set up in my gruntfile.js successfully at home.
I've run npm install grunt-cli -g and npm install inside my project on my WORK computer and installation has been successful each time. My only error messages on either are a lack of description and a repository field which, to my knowledge these aren't mandatory?
The node modules folder inside my repository indicates I have the following installed (as per my package.json)
grunt
grunt-contrib-compass
grunt-contrib-uglify
grunt-contrib-watch
matchdep
Now I'm pretty green to this command line stuff, so I may have overlooked something very obvious but I feel like I've tried every guide going to get this thing to work.
Despite running through the getting started steps/installing grunt documentation repeatedly, it seems no matter what I do the terminal will not pick up grunt as a recognized command.
Am I stupid or is this some other issue?
EDIT 1: contents of my package.json:
{
"name" : "xxxxxxxxx",
"version" : "xxxx",
"dependencies" : {
"grunt":"~0.4.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-compass": "~0.5.0",
"grunt-contrib-uglify": "~0.2.2",
"matchdep": "~0.1.2"
}
}
This is happening because you are using the Aptana Terminal, which needs the PATH variable to work out what is meant by grunt etc. A normal cmd prompt would work fine with the command npm install grunt-cli -g but in this context the terminal is unaware of what grunt is.
As per the following existing answer, you need to set up your Windows PATH variable to make the Aptana Terminal aware of the npm directory: https://stackoverflow.com/a/19137584/463205
C:\Users\Username\AppData\Roaming\npm
Closing the terminal and reopening it after setting the PATH correctly should enable you to run the command successfully.
Try to run
npm install grunt-cli -g
On your home computer.
-g means - install Grunt globally (not in the project node_modules folder), so it'll add grunt command to the bin folder which is used by nodejs console ( and you need to run node.js command prompt, not just arbitrary cmd)

Categories

Resources