Node.js: Editors and Modules

 In Miscellaneous

Our previous blog explained how and why Node is gaining popularity in Enterprise applications. It also explained how third party support is evolving along with a vibrant community.

This blog covers two important aspects of Node project development: Editors and Modules.

Functionalities and features provided by the editor help immensely in increasing the development speed. With a great editor, developers can concentrate on coding the logic rather than trying to get mundane things like syntax and signatures correct. So this blog covers which editors are available, what features they support and their maturity.

In Node world, modules are at the heart of any project. Getting them right is of utmost importance for maintainability, readability and quick troubleshooting. So let’s see how modules should be selected for a project, what are the guidelines and selection criteria.

Editors

As language for Node is JavaScript, pretty much any JavaScript editor can be used to type in the code. But here are some popular editors that are available.

Enide

Eclipse Node.JS IDE. This is customized Eclipse Mars for Node development. For a developer who is coming from a Java background, this is a natural choice. Also, it happens to provide many aspects of overall development process such as new project creation using templates, debugging support (break points, step into, step over etc.). As it is based on Eclipse, it obviously is a very good text editor.

SublimeText

This is another JavaScript editor. Although this is not free, it seems to be quite popular in the community, so that should tell you something about how people feel about it. It is quite powerful and has a feature rich text editor, but other things you might need such as template based project creation and debugging support are missing.

Microsoft Visual Studio Code

This is the editor from Microsoft. It is a decent text editor. It also comes with some aspects of IDE like integration with Git, Debugger etc.

Brackets

This is Adobe’s editor. Again this is a decent editor with inbuilt support for static code checks (lint) and allows you to preview in browser mode.

Of course apart from these editors, there are lots and lots of other commercial / open source / web based editors. But most of them still support basic functionalities. Features such as full-fledged code auto-completion, auto-suggestions, displaying signatures of functions from modules that are being used, displaying package.json file in user friendly way etc. are not generally available. So choose what bests suits your needs.

Modules

Creating Modules is the preferred way to design Node applications. In fact, Node design philosophy encourages you to write tiny modules that address only a specific problem. Modules encapsulate functionalities that can be shared across projects. Projects will refer any module through a file named package.json. This file has two most important basic fields name and version, along with many other fields such as description, keywords, license etc.

To explain in very simple words, modules use exports to make things available to external world

module.exports = function () {
console.log(‘bar!’);
}

And consuming code uses require to refer those modules.

var mname = require(‘<moduleName>’);

Such user written modules can even be published on npmjs repository independently. This strategy has resulted in just too many modules being available on npmjs repository! Just searching for word ORM on official npmjs repository returns around a thousand hits! Even though all of them might not be actually ORM frameworks, sheer count is mind-boggling. As per modulecounts site, there are more than 200,000 modules available on npmjs repository and the growth rate is highest amongst all others like Maven, PyPi, CPAN etc.

So in all likelihood, the functionality you are planning to develop might be just available as one of the modules. So the real question becomes: how do you choose a module?

For developing a commercial product, it’s best to avoid depending on modules built by some unknown developer, because you really can’t guarantee that you will get support in terms of fixes and enhancements in the future. As there is hardly any entry barrier over publishing modules on npmjs repository, many people just publish their modules without realizing that it’s their moral responsibility to provide support later on!

Apart from that, below are some guidelines that might help:

• Check what modules are shown in search results by npmjs repository.
• npmjs repository shows how many installs have happened in the last day, the last week, the last month, etc. It indicates what the response from the community is.
• npmjs repository provides list of most starred packages –https://www.npmjs.com/browse/star. Choose packages with the highest star rating.
• Check Github to see how many commits have happened for the module, how many open issues are there and when were they logged. Also check whether there are any pull requests, how many contributors are present and how many people are watching/starring it. Additionally, check whether there is there any documentation available.
• Another important thing worth looking at is whether the author maintains any kind of changelog to mention what has changed since last release.
• While searching for modules, be aware of confusing names; like just change in case!
For e.g., here are two modules with the exact same name with just different cases
https://www.npmjs.com/package/md5
https://www.npmjs.com/package/MD5
One is deprecated and other one is latest!!
• And most importantly, check what is the license for that module? It is clearly visible on module page on npmjs repository.

So to summarize, Editor Ecosystem is still in its nascent stage. But looking at the exposure Node is getting, it will surely mature very rapidly. Let’s watch out how it unfolds! Modules count will keep on exploding for some time and hence it will be very important to keep the above mentioned guidelines in mind while developing a real enterprise Node application.

Our next blog in the series will discuss best practices for making Node application production-ready.

Image Credits: nodejs.org

Recommended Posts

Start typing and press Enter to search

Contact Us
close slider
Contact Us

Yes, I would like Persistent to contact me on the information provided above. Click Here to read our full Privacy Notice.