There are several NodeJS modules out there which can be used to perform sentiment analysis on text, including sentiment, sentimental, sentiment-alyze and sentiword. Of course, all of these packages have to be used on the server side.

I recently found myself wanting to use sentiment analysis on the client side, and so went searching for a browser-based sentiment analysis package. There isn't too much out there, but I did come across an excellent browser-based package called Sentimood.js. According to the GitHub readme.md file, it is effectively the same as the NodeJS sentimental package, but edited/translated for browser-side use.

Setup

Sentimood is incredibly easy to use. You can use bower to install the package with bower install sentimood. Alternatively, just copy the sentimood.js file from the GitHub repository to the desired location in your repository. Once you have done this, you will need to reference the script as follows:

<script type="text/javascript" src="your-path/sentimood.js"></script>

Once referenced, Sentimood is very intuitive. You can use it as follows:

var sentimood = new Sentimood();
var analysis = sentimood.analyze('Node is good');
var positivity = sentimood.positivity('Python is excellent');
var negativity = sentimood.negativity('PHP is bad');

To get to grips with Sentimood, it is actually best to mess around with it in the REPL. To do this, open your REPL by running the node command from your project root. You can then load the contents of sentimood.js into the REPL using:

.load components/sentimood/sentimood.js

Your path to sentimood.js may be different if you have different Bower settings, or if you haven't used Bower for installation. One disadvantage of this load method is that it places the code from the sentimood.js file into your Node REPL history so you will not be to access your recent command history (unless you press the up arrow a LOT).

Once Sentimood is loaded into your REPL, you can play with it easily.

> var sentimood = new Sentimood();
undefined
> sentimood.analyze('Node is good')
the phrase is
Node is good
{ score: 3,
  comparative: NaN,
  positive: 
   { score: 3,
     comparative: 3,
     words: [ 'good' ] },
  negative: { score: 0, comparative: NaN, words: [] } }
> sentimood.analyze('Node is bad')
the phrase is
Node is bad
{ score: -3,
  comparative: NaN,
  positive: { score: 0, comparative: NaN, words: [] },
  negative: 
   { score: 3,
     comparative: 3,
     words: [ 'bad' ] } }

Of course, whenever you use a sentiment analysis tool you always have to understand that it may have limitations. For example, Sentimood struggles as soon as I use a double-negative:

> sentimood.analyze('Node is not bad')
the phrase is
Node is not bad
{ score: -3,
  comparative: NaN,
  positive: { score: 0, comparative: NaN, words: [] },
  negative: 
   { score: 3,
     comparative: 3,
     words: [ 'bad' ] } }

That said, Sentimood appears to be the only client-side sentiment analysis NPM package available. I have found it very useful for my work - hopefully you will find it helpful too.