10 creative Node.js modules which will enhance your skills and your application

Over recent years Node.js has become more and more popular. It is now often used for developing the server side of web applications, or in general during the development process. At the time of writing, the homepage of npm – the package manager for Node.js – lists over a quarter of a million modules.

I’ve put together a list of the ones I find useful in my daily work as a web and software developer, from image manipulation, string validation and PDF generation to minification, logging and the creation of command line applications.

1. Manipulate images – GraphicsMagick

GraphicsMagick provides a comprehensive collection of utilities, programming interfaces, and GUIs, to support file format conversion, image processing, and 2D vector rendering. GraphicsMagick and ImageMagick are two popular tools for creating, editing, composing and converting images. Thanks to the Node.js module gm you can use both tools directly from within your JavaScript code. The module supports all the typical image operations – resizing, clipping and encoding to name just a few.

const gm = require('gm');
gm('/path/to/image.jpg')
  .resize(500, 250)
  .autoOrient()
  .write(response, error => {});

2.  Process markdown files

Markdown is a popular text format written in an easy-to-read way and is convertible to HTML. It is a markup format that has been popularized by sites such as Github and Stack Overflow. Today we will be building an app that let’s us view the raw markdown on the left side and the converted markdown (to HTML) on the right side. We will also allow multiple people to work on the same markdown document at the same time via a shareable URL and all changes will be saved.
Showdown is a Javascript Markdown to HTML converter, based on the original works by John Gruber. Showdown can be used client side (in the browser) or server side (with NodeJs).

Live DEMO

Check a live Demo here http://demo.showdownjs.com/

3.  Process CSV files

 

A CSV parser for node.js

To install node-csv, use npm:

$ npm install node-csv

Usage

var csv = require('node-csv').createParser();

var csv_str = "1,2,3\n4,5,6";

csv.parse(csv_str, function(err, data) {

    console.log(data); //Outputs: [[1,2,3],[4,5,6]]
    
});

// or

csv.parseFile('./test.csv', function(err, data) {
    console.log(data);
});

createParser() takes 3 optional params – delimiter, quote_char, quote_escape

E.g. to parse tab separated values where fields are wrapped with quotes (“) and quotes are escaped with ”

var csv = require('node-csv').createParser('\t', '"', '\\');

node-csv can also convert each row to an object based on the column names in the first row, e.g.

test.csv

id,user,pass
1,foo,bar

parse.js

var csv = require('node-csv').createParser();

csv.mapFile('./test.csv', function(err, data) {

    console.log(data); //Outputs: [ { id: '1', user: 'foo', pass: 'bar' } ]
    
});

4. Format dates

Moment.js is a great alternative to JavaScript's Date object

Moment.js is a great alternative to JavaScript’s Date object

The standard JavaScript API already comes with the Date object for working with dates and times. However, this object is not very user-friendly when it comes to printing and formatting dates. On the other hand, Moment.js offers a clean and fluid API, and the resulting code is very readable and easy to understand.

moment()
  .add(7, 'days')
  .subtract(1, 'months')
  .year(2009)
  .hours(0)
  .minutes(0)
.seconds(0);

In addition, there is an add-on available for parsing and formatting dates in different time zones.​

 

5. nodemailer

If you ever need to send email, don’t send it yourself — use a transactional email service, such as SendGrid. It comes with some great features, such as the ability to make a nice template that wraps all of our emails. Nodemailer is the package that lets us send simple messages to SendGrid.

 

6. prerender-node

Remember that Angular thing we use? It sucks for SEO because most search engines can’t understand it. In comes prerendering to the rescue. With it, web crawlers can easily see a non-Angular version of your website because the prerenderer estimated what it looks like. Turn off JavaScript in your web browser next time you browse Croissant and you’ll see what we mean.

 

7. Restify

Restify is a node.js module that enables creating correct REST web services. It helps build “strict” API services that are maintainable and observable. The framework gives an absolute control over interactions with HTTP and full observability into the latency and characteristics of the applications you make.

Restify: a framework to make it super simple to build a REST API with Node. It is very similar to the most popular Node web framework Express.js, but with a specific focus on building an API. This often overlooked tool can prove extremely valuable, particularly in the early stages of development. – Emily Rose, Lead Developer Evangelist at Salesforce.

 

8. Node inspector

Node inspector is an effective Node.js debugger interface that uses the Blink Developer Tools. It provides a wide set of powerful features that help debug Node.js code with ease.

Node inspector is vital for anyone who wants to debug their Node.js code. It provides the same amazing tools developers have come to expect in the browser (Chrome) but for Node: breakpoints, watch statements, REPL, profiling, etc. – Jordan Kasper, Front End Engineering Instructor and Mentor Lead at The Iron Yard.

Hope the list above will help you with your future Node.js projects. All the recommendations come from experts that have tested them in action at top tech companies. If you’re also interested in other companies that used Node.js in their production, check out my previous entry.

 

9. slug

This is the library that turns “Hello There” into “hello-there”, perfect for making dynamic titles into URL-friendly links. We use this for taking the names of our venues and making that unique link that you can share with your buddies so they know where to find you.

 

10. stripe

Time to get paid. Stripe is our payment processor for credit cards. They’re nice enough to store customer credit card information in a PCI-compliant way so we don’t have to. We use their sdk to put cards on file and make charges.

 

 

 

Your email address will not be published.