Node.js is a run-time environment used for executing JavaScript outside the browser. Npm is a JavaScript package manager commonly used for installing packages for Node.js.
Introduction
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Latest LTS Version: 12.18.4 (includes npm 6.14.6) Download the Node.js source code or a pre-built installer for your platform, and start developing today. Oct 21, 2018.
In this article, you will learn how to install Node.js and npm on Mac or Linux. You will also learn how to verify the installation, run Node.js code, and how to update Node.js and npm.
When youâre finished, youâll be able to run Node.js code on Mac or Linux computer.
Prerequisites
To follow this tutorial successfully, youâll need the following:
Step 1 â Install Node.js and npm on Mac or Linux
There are a couple of ways to install Node.js on Mac or Linux. The most recommended method and also my favorite method to install Node.js and npm is to use Node Version Manager(nvm).
Using nvm has the following benefits:
So letâs now install nvm. Copy and paste the command below into your terminal.
Info: If your on Mac, open your
~/.bash_profile or create a new one if the ~/.bash_profile file does not exist. Make sure you add source ~/.bashrc in the file and save. https://textnew184.weebly.com/blog/nero-burning-rom-download-mac.
Now letâs verify if
nvm was installed successfully.
Your terminal should display the current version of nvm. At the time of writing, the current version is 0.35.2. So this is the output I got.
Note: On Linux, if you get
nvm: command not found or no feedback, close your terminal and open a new terminal and enter the nvm --version again. How to download snip mac. If you using ssh to access linux, you might need to restart your session.
Tip: On Mac, if you are having any issues with the
nvm command not working, check out this link
Lets now install Node using nvmâs install command.
Once installed, set the installed version as the default.
Info: You need to set the default version because nvm forgets the node version in a new terminal session. You can learn more about the issue here.
Step 2 â Verify Node.js and npm installation
Verify if Node.js and npm were successfully installed.
Type
node -v . It will display the current Node.js version.
Type
npm -v to display the current npm version.
Your output should look similar to mine. Note that the versions will be different since you might be reading this tutorial when new versions came out.
Running Node.js Code on Mac or Linux
There are two ways to run Node.Js code:
Node.js REPL
REPL stands for Read-Evaluate-Print-Loops. It is an interactive shell that allows experimentation of JavaScript code. It works the same way as the web browser console.
To access the Node REPL, type
node in the terminal.
The REPL prompt will be opened where you can enter the JavaScript code.
License
The
> sign is there to let you know that the code entered will be immediately evaluated when you press enter.
Npm (software) - Wikipedia
To exit out of the REPL, type
.exit or press CTRL+D once. You can also exit out by pressing CTRL+C twice.
Running Node.js Scripts on the Terminal
This method is the one that is commonly used to run Node. You will write Node.js code in a file with an extension of
.js and run it in the terminal using the node command.
Letâs see this in action by creating a directory named
node.js in our home directory.
mkdir is a command used for creating directories
Letâs go into the
nodejs directory.
Your terminal should now show you are in the
node.js directory.
Create a file
first-program.js . For simplicityâs sake, we will use Nano which is a terminal text editor.
Enter the following code in
first-program.js in the Nano editor.
Hold CTRL+O and then press
enter to save the file.
Exit out of the editor by holding
CTRL+X .
Letâs now run the code in
first-program.js :
Your output should look like below.
I hope you have understood how to run Node.js code on your Mac or Linux system.
Next, we are going to learn how to update Node.js and npm using nvm.
How to Update Node.js and npm using nvm
To update to the latest version Node.js and npm. Type the following:
To update to the latest LTS(Long Term Support) version. Type the following:
Conclusion
In this article, you learned how to install and update Node.js and npm on Mac or Linux. We also looked at different ways on how to run Node.js code. I hope you are now confident to run Node.js scripts on your computer on your Mac or Linux computer.
If you have any insights or suggestions, feel free to leave a comment. I would love to hear from you.
![]()
In this tutorial, Iâll be teaching you how you can install Node.js on windows, mac or linux in under 15 minutes. https://textnew184.weebly.com/quickbooks-enterprise-2016-download-mac.html.
Node is an open-source runtime environment for javascript. It is a cross-platform environment providing its support for Mac, Windows and Linux. It runs Chromeâs V8 javascript engine, outside the browser, and because of this, it is very powerful.
It runs in a single process, without creating a new thread for every request. Node JS
How Does a Node App Look?
How to Install Node.js?
These tools are required for developing a Node.js application on any platform.
*NPM gets installed automatically when you install Node on your system.
Installation on Windows and MAC
To download node, you just need to visit the nodeâs official website and download the LTS version of node.
Once, downloaded, youâll see an installer similar to this.
Hit install it as you install any other application on your Windows or Mac. Enter your system password if prompted.
And once done, the installer will prompt you a success message. You can now go ahead and delete the installer.
Installation on Linux
To install Node on your Ubuntu machine, run the following command:
Now save the code and hit
Ctrl + ~
This will open an integrated terminal of vs code in the same directory and from here you can directly run your js code.
Simply run the following command and hit enter.
node app.js server running at http://127.0.0.1:3000/
you can now visit
http://127.0.0.1:3000/ to check your node app running.
well, this was all about setting up your system for js development. if you stuck into any kind of error, donât forget to google it and try to debug it on your own.
this will teach you how to debug on your own as someone might have faced a similar problem earlier.
if you still donât find any solution for your problem, you can ask your doubt in the commentâs section below and weâll get back to you.
you may also like:Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
February 2021
Categories |