npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sentimentjs

v1.0.6

Published

> A sentiment analysis library for tweet objects and strings

Downloads

9

Readme

sentimentjs

A sentiment analysis library for tweet objects and strings

This sentiment library is used in our Crowd Parser app, which analyzes Twitter sentiment. Check it out here:

Crowd Parser

Our goal with sentimentjs is to improve upon other sentiment libraries by including "layers" that check for factors that other sentiment libraries might ignore or miss.

For example, our "emoticons layer" specifically looks for emoticons in a string or tweet and gauges sentiment based upon its findings.

All Layers:

  1. Base common words layer
  2. Emoticon layer
  3. Slang layer

Our base word lists come from renowned researchers Minqing Hu and Bing Liu, who authored this paper

Minqing Hu and Bing Liu. "Mining and Summarizing Customer Reviews." Proceedings of the ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (KDD-2004), Aug 22-25, 2004, Seattle, Washington, USA

Installation

npm install sentimentjs

Usage

Analyze an array of strings

var sentiment = require('sentimentjs');

var arrayOfStrings = ['I love deep dish pizza :)', 'I hate brussel sprouts >:('];

var sentimentStringsAnalysis = sentiment.stringsArray(arrayOfStrings);

console.log(sentimentStringsAnalysis);

Running the above will return an object that has this format:

{
  stringsWithAnalyses: [
  {
    text: 'I love deep dish pizza :)',

    baseLayerResults: {
      positiveWords: ['love'],
      negativeWords: [],
      score: 1
    },

    emoticonLayerResults: {
      positiveWords: [':)'],
      negativeWords: [],
      score: 1
    },

    overallResults: {
      score: 2
    }
  },
  {
    text: 'I hate brussel sprouts >:(',

    baseLayerResults: {
      positiveWords: [],
      negativeWords: ['hate'],
      score: -1
    },

    emoticonLayerResults: {
      positiveWords: [],
      negativeWords: ['>:('],
      score: -1
    },

    overallResults: {
      score: -2
    }
  }
  ]
}

Analyze an array of tweet objects

Twitter API Credentials

To analyze tweet objects, you will need to have Twitter API credentials (keys, token, and secret). The README for our Crowd Parser app contains instructions for setting this up.

Crowd Parser

To set up the Twitter API with a Node server, this is how we do it:

var Twit = require('twit');

var T = new Twit({
  consumer_key: 'ENTER YOURS HERE', 
  consumer_secret: 'ENTER YOURS HERE', 
  access_token: 'ENTER YOURS HERE', 
  access_token_secret: 'ENTER YOURS HERE'
});

Using sentimentjs with tweets

var sentiment = require('sentimentjs');

T.get('search/tweets', {q: 'football', count: 50, result_type: 'mixed'}, function(err, data) {
  var sentimentTweetsAnalysis = sentiment.tweetsArray(data);

  console.log(sentimentTweetsAnalysis);
});

Running the above will return an object that has this format:

{
  tweetsWithAnalyses: [
  {
    created_at: ** DATE CREATED ** ,
    id: ** TWEET ID **,
    text: ** TWEET TEXT **,
    username: ** USERNAME **,
    followers_count: ** NUMBER OF FOLLOWERS **,

    baseLayerResults: {
      positiveWords: [ ** POSITIVE WORDS ** ],
      negativeWords: [ ** NEGATIVE WORDS ** ],
      score: 1
    },

    emoticonLayerResults: {
      positiveWords: [ ** POSITIVE EMOTOCONS ** ],
      negativeWords: [ ** NEGATIVE WORDS ** ],
      score: -2
    },

    slangLayerResults: {
      // SAME FORMAT AS ABOVE
    },

    overallResults: {
      score: -1
    }
  },
  {
    // TWEET #2
    // ** SAME AS ABOVE **
  }
  ]
}

Using the Example

First, navigate to the example directory.

cd example

Next, install dependencies:

npm install -g bower
npm install
bower install

Next, start the server:

node server

Finally, open http://localhost:3000 in your browser.

To test, edit the array of strings in server.js. You can also try to use the tweetsArray method and enter an array of tweets.

var results = allLayersAnalysis.stringsArray(['I love dogs. They are wonderful! 😍 😍', 'I hate brussel sprouts. They are terrible. 😾', 'This is great! But also bad.']);

Change the above array for testing. Again, the sample output can be displayed like this:

There is a function in index.html to highlight the positive and negative words in the text.

Contributing

We welcome you to join us in creating a better sentiment library! Our library is still in an infant stage, so contributions would be greatly appreciated!