Recently I have been playing with Node.js and for every developer, getting the perfect IDE/Editor and setting up the workspace is very important. Here’s how I got my set up ready:
I am using Xubuntu 14.04.3 LTS. So the steps that I am going to share will work in any of the Ubuntu flavours.
1. Installing Node.js: Node.js is already there in the default Ubuntu 14.04 repository and the version is 0.10.25. If you need more updated version, you have 2 ways. You can either download it from the official Node.js site, or you can follow this tutorial and add a third-party repository or use nvm to get it installed. In the first case, it will not be auto-updated though. However, I chose to use the default repository version as I didn’t see the point in going through all these hassle unless I specifically want a feature that is only available in the newer versions.
To install the default nodejs in Ubuntu 14.04, type the below command (or use your favourite package manager to install the package):
sudo apt-get install nodejs
2. Installing Atom editor: While this is something that is not exactly required for Node.js and Node.js can be developed with any editor, I preferred Atom for it’s set of features and open source nature. To install Atom on my system, I used the WebUpd8 PPA so that I get regular updates and I don’t need to build from source to install the latest one. To use the WebUpd8 PPA, use the below commands:
sudo add-apt-repository ppa:webupd8team/atom
sudo apt-get update
sudo apt-get install atom
3. Configuring Atom to run Node within Atom: While you can write your code in Atom and run it from the terminal separately, I prefer to run it within the IDE itself, it saves a lot of Alt + Tab. It’s not supported by default, you need to add a package to get this functionality.
Open Atom and go to Edit -> Preferences -> Install. Search for the package atom-runner and hit Install. Atom-runner will now be installed. Although you need to change the default configuration to run Node using atom-runner. The reason is that in Ubuntu, the name of the Node.js package (hence the command) is not node (it is the default everywhere else) due to the conflict with some other package, rather it’s nodejs.
To update the configuration, open ~/.atom/config.cson with your favourite text editor where ~ stands for your home directory. Paste the below lines:
Do take care of the indentation. The first line of the above text should be indented a little right and the next two lines should each be indented further right.
If you do the above steps correctly, you have your Atom editor ready to write some Node. Create a new file and name it to somename.js. Paste console.log(‘It’s working.’) in the editor and save it. Press Alt + R and it should print the output in a new tab.
That’s it for now. I will be adding more contents to it as I go with Node. Let me know in the comments if you have better suggestions about Node.js development. I will be sure to take a look.