How to Install Node.js and NPM on Mac OS
How to Install Node.js and NPM on Mac OS
How to Install Node.js and NPM on Mac OS |
Node JS is the popular Javascript runtime environment that is widely used by many developers, and npm is the accompany package manager for the Node.js environment and Javascript. When you install Node.js, you will find npm is installed as well, thus if you want npm you need to install NodeJS. There are several ways to install Node.js and NPM on the Mac, including using a prebuilt packaged installer, or by using Homebrew. This tutorial will cover both, and either approach should work find on any modern version of MacOS system software.
How to Install Node.js and NPM on Mac OS
The easiest way to install node.js and npm is with the Homebrew package manager, which means first you will need to first if you have not done so already. Its always a good idea to update Homebrew before installing a Homebrew package, so run the following command to do that: Assuming you already have Homebrew on the Mac, then you can run the following command into the Terminal application to install both Node.js and npm: Installing NodeJS / NPM via Homebrew is arguably easier than using any other method, and it also makes it simple to keep node.js and npm updated.
It also has the added benefit of making it relatively simple to uninstall down the road if you decide you no longer need it. If you dont want to use Homebrew for whatever reason, the other next easiest option is to use a the prebuilt installer from nodejs.org: You can run the installer like any other installation package on the Mac.
After you have installed node.js with npm, you can confirm that the two are installed by issuing either command with a -v flag to check the version: and Once the node.js package is installed on the Mac you can test its working by starting a simple web server.
How to Install Node.js and NPM on Mac OS
Create a file named app.js that contains the following code syntax: const hostname = 127.0.0.1; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader(Content-Type, text/plain); res.end(Hello from NodeJS\n); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); Save that app.js file to the current directory, then you can start the web server with the following command: Then launch a web browser (your default or otherwise) and go to the following URL: You should see a message stating Hello from Node.js.
That simple node.js web server is sort of like except of course its using node rather than python. Speaking of Python, if youre installing Node.js and NPM you may also be interested in too. You can also install and use Grunt CLI task runner to test node and npm, which can be installed through npm: You can then run grunt from the command line. That should just about cover the basics of installing NodeJS and npm on a Mac. If you have any other tips, tricks, suggestions, or advice, feel free to share them in the comments below.
How to Install Node.js and NPM on Mac OS
No comments