{"_id":"59d0273a783f1a0010dad643","project":"568bdc1483d2061900d86cdc","version":{"_id":"59a72290d61777001b6c42c3","project":"568bdc1483d2061900d86cdc","__v":19,"createdAt":"2017-08-30T20:39:44.453Z","releaseDate":"2017-08-30T20:39:44.453Z","categories":["59a7236e3fe4d90025117c10","59a72eb6cb0db3001b84cfe2","59a734eb757d030019b85af8","59c0243b1b2d07001a9d2b76","59c035e42126e10028effb12","59c06c40df5b3c0010584a13","59c1a5852cabe5002641a3e7","59c2fb00b2b45c0010b7a3d7","59c32ceb9aea850010ac4130","59c32e6e190c90003cb0d12f","59c33affb2b45c0010b7aa23","59c7dfa457bd8200105444dc","59c7e975c50cf30010d712a0","59cffdef0cd4dd0010294d54","59d0622ca91a810032c8f60c","59d06733c1aec60026253065","59d174d44ac471001a07b123","59d5a5e323e6e800103defb2","59ecf1d8ed507c001c52b255"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"0.0.0","version":"0"},"category":{"_id":"59a72eb6cb0db3001b84cfe2","project":"568bdc1483d2061900d86cdc","version":"59a72290d61777001b6c42c3","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-08-30T21:31:34.201Z","from_sync":false,"order":0,"slug":"knowledge-base","title":"Getting Started"},"user":"58cc41f21751ce2f003be3b7","__v":0,"parentDoc":null,"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-09-30T23:22:34.923Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"To download NodeJS for macOS, head over to https://nodejs.org/en/download/current/\n\nAt the time of writing this article, the current version of NodeJS is 7.2.0 and NPM is 3.10.9.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/470a0fa-Screen_Shot_2016-12-05_at_3.51.51_PM.png\",\n        \"Screen Shot 2016-12-05 at 3.51.51 PM.png\",\n        1195,\n        891,\n        \"#dde8e3\"\n      ]\n    }\n  ]\n}\n[/block]\nDownload and run the **macOS Installer (.pkg)**\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": []\n    }\n  ]\n}\n[/block]\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/0185ff7-Screen_Shot_2016-12-05_at_3.42.26_PM.png\",\n        \"Screen Shot 2016-12-05 at 3.42.26 PM.png\",\n        732,\n        550,\n        \"#e9e9e9\"\n      ]\n    }\n  ]\n}\n[/block]\nBy default NodeJS will install to `/usr/local/bin/node` and NPM will install to `/usr/local/bin/npm`\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/e0ceef3-Screen_Shot_2016-12-05_at_3.40.07_PM.png\",\n        \"Screen Shot 2016-12-05 at 3.40.07 PM.png\",\n        732,\n        550,\n        \"#e9e9e8\"\n      ]\n    }\n  ]\n}\n[/block]\nYou can check that NodeJS and NPM are installed correctly by confirming their version numbers from **Terminal** by running `node -v` and `npm -v`.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/450ca18-Screen_Shot_2016-12-05_at_3.53.34_PM.png\",\n        \"Screen Shot 2016-12-05 at 3.53.34 PM.png\",\n        617,\n        478,\n        \"#040404\"\n      ]\n    }\n  ]\n}\n[/block]\nYou can test NodeJS by running it interactively. From Terminal enter `node`, then `console.log(\"Helloworld!\");`\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/30c005a-Screen_Shot_2016-12-05_at_4.15.23_PM.png\",\n        \"Screen Shot 2016-12-05 at 4.15.23 PM.png\",\n        589,\n        450,\n        \"#040404\"\n      ]\n    }\n  ]\n}\n[/block]\nYou will need to complete the next section if you wish to install npm packages globally.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Installing Node modules globally\"\n}\n[/block]\nYou can install some npm packages globally, such as the [droplit.io CLI](https://www.npmjs.com/package/droplit-cli), to run them from any directory. \n\n`npm install droplit-cli -g`\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/689c481-Screen_Shot_2016-12-05_at_9.13.11_PM.png\",\n        \"Screen Shot 2016-12-05 at 9.13.11 PM.png\",\n        589,\n        492,\n        \"#eff0ec\"\n      ]\n    }\n  ]\n}\n[/block]\nHowever, you may encounter an error like this when installing npm packages globally.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/f52421c-Screen_Shot_2016-12-05_at_6.34.34_PM.png\",\n        \"Screen Shot 2016-12-05 at 6.34.34 PM.png\",\n        617,\n        478,\n        \"#e2d5d6\"\n      ]\n    }\n  ]\n}\n[/block]\nThere are a few ways to solve this issue according to [docs.npmjs.com](https://docs.npmjs.com/getting-started/fixing-npm-permissions). We prefer Option 2 as it does not require changing directory ownership, which may be a security risk.\n\nFirst, change the install location of global packages.\n```\nmkdir ~/.npm-global\nnpm config set prefix '~/.npm-global'\n```\n\nFinally, create/edit `.bashrc` to add the new directory to your `PATH`. \n\n```\necho \"export PATH=~/.npm-global/bin:\\$PATH\" >> ~/.bashrc\n```\n\nRestart your terminal and you should be able to install and use global packages. \n[block:callout]\n{\n  \"type\": \"info\",\n  \"title\": \"You can use .bash_profile instead of .bashrc if you wish.\",\n  \"body\": \"The `.bash_profile` is only executed for a login-shell, whereas `.bashrc` is executed for every new shell instance\"\n}\n[/block]","excerpt":"","slug":"install-nodejs-on-mac-os","type":"basic","title":"NodeJS Setup: MacOS"}

NodeJS Setup: MacOS


To download NodeJS for macOS, head over to https://nodejs.org/en/download/current/ At the time of writing this article, the current version of NodeJS is 7.2.0 and NPM is 3.10.9. [block:image] { "images": [ { "image": [ "https://files.readme.io/470a0fa-Screen_Shot_2016-12-05_at_3.51.51_PM.png", "Screen Shot 2016-12-05 at 3.51.51 PM.png", 1195, 891, "#dde8e3" ] } ] } [/block] Download and run the **macOS Installer (.pkg)** [block:image] { "images": [ { "image": [] } ] } [/block] [block:image] { "images": [ { "image": [ "https://files.readme.io/0185ff7-Screen_Shot_2016-12-05_at_3.42.26_PM.png", "Screen Shot 2016-12-05 at 3.42.26 PM.png", 732, 550, "#e9e9e9" ] } ] } [/block] By default NodeJS will install to `/usr/local/bin/node` and NPM will install to `/usr/local/bin/npm` [block:image] { "images": [ { "image": [ "https://files.readme.io/e0ceef3-Screen_Shot_2016-12-05_at_3.40.07_PM.png", "Screen Shot 2016-12-05 at 3.40.07 PM.png", 732, 550, "#e9e9e8" ] } ] } [/block] You can check that NodeJS and NPM are installed correctly by confirming their version numbers from **Terminal** by running `node -v` and `npm -v`. [block:image] { "images": [ { "image": [ "https://files.readme.io/450ca18-Screen_Shot_2016-12-05_at_3.53.34_PM.png", "Screen Shot 2016-12-05 at 3.53.34 PM.png", 617, 478, "#040404" ] } ] } [/block] You can test NodeJS by running it interactively. From Terminal enter `node`, then `console.log("Helloworld!");` [block:image] { "images": [ { "image": [ "https://files.readme.io/30c005a-Screen_Shot_2016-12-05_at_4.15.23_PM.png", "Screen Shot 2016-12-05 at 4.15.23 PM.png", 589, 450, "#040404" ] } ] } [/block] You will need to complete the next section if you wish to install npm packages globally. [block:api-header] { "type": "basic", "title": "Installing Node modules globally" } [/block] You can install some npm packages globally, such as the [droplit.io CLI](https://www.npmjs.com/package/droplit-cli), to run them from any directory. `npm install droplit-cli -g` [block:image] { "images": [ { "image": [ "https://files.readme.io/689c481-Screen_Shot_2016-12-05_at_9.13.11_PM.png", "Screen Shot 2016-12-05 at 9.13.11 PM.png", 589, 492, "#eff0ec" ] } ] } [/block] However, you may encounter an error like this when installing npm packages globally. [block:image] { "images": [ { "image": [ "https://files.readme.io/f52421c-Screen_Shot_2016-12-05_at_6.34.34_PM.png", "Screen Shot 2016-12-05 at 6.34.34 PM.png", 617, 478, "#e2d5d6" ] } ] } [/block] There are a few ways to solve this issue according to [docs.npmjs.com](https://docs.npmjs.com/getting-started/fixing-npm-permissions). We prefer Option 2 as it does not require changing directory ownership, which may be a security risk. First, change the install location of global packages. ``` mkdir ~/.npm-global npm config set prefix '~/.npm-global' ``` Finally, create/edit `.bashrc` to add the new directory to your `PATH`. ``` echo "export PATH=~/.npm-global/bin:\$PATH" >> ~/.bashrc ``` Restart your terminal and you should be able to install and use global packages. [block:callout] { "type": "info", "title": "You can use .bash_profile instead of .bashrc if you wish.", "body": "The `.bash_profile` is only executed for a login-shell, whereas `.bashrc` is executed for every new shell instance" } [/block]