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 🙏

© 2024 – Pkg Stats / Ryan Hefner

meddelare-express

v1.0.4

Published

Node.js Express web server middleware for in-app, self-hosted Meddelare within your current server.

Downloads

16

Readme

Meddelare Social Buttons Node.js Express Middleware meddelare-node-express


⚠️ The Meddelare Social Buttons project has been shut down as of 2020-12-07. No updates will be made and the source code will possibly be deleted in the future. Please download what you need as soon as possible.


Install custom social share counters on your website with your own hosted solution, which only makes a single API request and loads minimal or zero assets to display the counters.

A screenshot of the button example

Check out meddelare.com and view examples on meddelare.com/meddelare-examples.


Node.js Express middleware

Node.js Express web server middleware for in-app, self-hosted Meddelare within your current server.

Features

  • Completely customizable user interface design -- use layout, logotypes, animations of your own choice.
  • A single API call to get counts from multiple social networks, delivered as JSON or JSONP.
  • Calls social networks in parallel from the server, making it (approximately) as fast to get the count from one as several at once.
  • No third party resources required – you can host both the social buttons server and any resources yourself.
  • Blocks social networks' user tracking by proxying calls until the user decides to click a share button.
  • Super-fast in-memory cache keeps the most recent results per network and url.
  • Easy to deploy and prepared for content delivery network (CDN) proxies.

Getting started

Install package in your Express app folder

npm install --save meddelare-express

Add the MeddelareExpress to your Express app

var express = require("express"),
    app = express(),
    PORT = process.env.PORT || 5000;

var MeddelareExpress = require("meddelare-express"),
    meddelareExpress = new MeddelareExpress();

// Choose your own directory path for the middleware.
app.use("/meddelare/", meddelareExpress.getRouter());

app.listen(PORT, function() {
    console.log("Listening on " + PORT);
});

Response

See this example API call. The response is delivered as JSON, or JSONP if you specify a callback.

{
  "facebook": 5281,
  "googleplus": 42,
  "twitter": 8719
}

HTML Widgets

View examples on meddelare.com/meddelare-examples.

We would love to feature your widget design!
Please submit your design in a pull request to meddelare-examples and we will add it to our list.

You can do anything you want to display your share counts when using the API. Below is a very simple example showing the count per network -- see this example API call with text. Note that we are using a CloudFront distribution domain in the examples.

<!DOCTYPE html>
<html>
  <body>
    <h3>Twitter</h3>
    <span id="twitter"></span>
    <h3>Facebook</h3>
    <span id="facebook"></span>
    <h3>Google Plus</h3>
    <span id="googleplus"></span>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
    <script>
      var url = "https://meddelare.com/";
      var encoded = encodeURIComponent(url);
      var networks = ["facebook" , "twitter" , "googleplus"];

      $.ajax("https://d12cncu17l9pr5.cloudfront.net/?networks=" + networks.join(",") + "&url=" + encoded, {
        success: function (res, err) {
          $.each(res, function (network, value) {
            $("#" + network).text(value);
          });
        }
      });
    </script>
  </body>
</html>

Options

Options are passed using query parameters in the url.

Networks
Currently Twitter, Facebook and Google Plus are supported.

Use the networks query parameter to specify which ones you want to use as a comma-separated list (no spaces), for example networks=facebook,twitter,googleplus or networks=facebook.

Url (optional)
Use the url parameter to specify the address which you want to retrieve the number of shares for, for example https://meddelare.com/.

  • The value needs to be URL-encoded.
    • This prevents problems when looking up values for pages with, for example, parameters separated by &.
    • For example https://meddelare.com/ becomes https%3A%2F%2Fmeddelare.com%2F when using javascript: encodeURIComponent("https://meddelare.com/").
  • You can use your domain root, or a more specific url pointing to a specific page.

If you don't specify a url then the server will try to get the referring url's (HTTP Referer header) share count. This makes it easy to dynamically get the counts for the page currently open in the browser.

Callback (optional)
Specify the callback parameter to have the results delivered as JSONP instead of plain JSON.

Configuration

Configure the middleware instance at creation time.

HTTP cache time
TODO httpCacheTime: 4 * 60

Router options
TODO (hidden feature)

routerOptions: {
    caseSensitive: true,
    strict: true,
},

Social button counts
TODO meddelareCounters: {}

Logger
TODO logger: {}

Content delivery networks

If you want to reduce your server load it would be wise to throw up a cache, such as CloudFront, in front.

In CloudFront, just make sure you to inherit cache control directives from the server, enable query string forwarding and whitelist Origin HTTP headers. Either use your CloudFront distribution domain to access the API server or CNAME it with a custom domain of your choice.

Thanks

Many thanks goes out to Taskforce for their social-buttons-server (released into the Public Domain) -- especially the creator @thomasdavis and contributor @beaugunderson. This software, meddelare-node-express, is based on their work.


Copyright (c) 2015 Team Meddelare https://meddelare.com/ All rights reserved.

When using meddelare-node-express, comply to the MIT license.