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

linkmeup

v1.1.4

Published

The easiest connection between microservices in NodeJS

Downloads

59

Readme

LinkMeUp - the easiest way to link NodeJS microservices with each other

Currently the project is at the "Working prototype" stage.

Features

  • Calling remote methods

  • Transfer the buffer in binary

  • Calling long methods with feedback functions

  • Calling methods with stream arguments

Install

yarn install linkmeup

How to use it

First, you need two projects - root service project and microservice project. A project with a microservice will be called a server because it accepts requests from the root.

In microservice project create server instance, like

import { createServer } from 'linkmeup'
const server = new createServer("imageConverter")

Then, add some async method for your server and launch the server, like:

/** Convert image to another image */
server.addMethod("processImage", async (image: Buffer) => {
  const result = await processImage(image)
  return result
})

...

server.listen(7800, 'localhost')

In the second step, we need to build a file with types to send to the client. You can do this using the command line, and then modify it if necessary:

yarn linkmeup generate

This will result in the file linkmeup.d.ts with the following content:

declare module "linkmeup" {
    interface LinkMeUpClients {
        imageConverter: {
            /** Convert image to another image */
            processImage(image: Buffer): Promise<Buffer>;
        };
    }
}
export {}

This file needs to be placed in the client to pull up the right types. Usually, it is enough to place it anywhere for the typescript to pick it up.

That's it, now all that's left is to connect to our server:

import { createClient } from 'linkmeup'

const client = createClient("imageConverter", "http://localhost:7800")

The methods are called as usual methods with the names that were assigned on the server:

const resultImage = await client.processImage(image)

How to call long methods

In the previous section, when calling methods, the usual HTTP call is used, which waits for the completion of the function. This is a simple and fast scheme, but your request may drop by timeout (e.g. it will be killed by nginx).

To avoid this, you can use long methods. In this case, a request is sent, which immediately receives a response with the requestId. Then, at a certain interval, the client asks the server about the status of the request. This also allows you to make a callback on the server.

Example: You upload a video to a microservice for compression. The video is long and takes a long time to process, in addition you would like to know what percentage of it has been processed. To do this, you declare a long method and callback every time you update your progress.

Extend last example. We use addLongMethod instead addMethod

server.addLongMethod("processVideo", async (video: Buffer, callback: (progress: number) => void) => {
  const result = await processVideo(video, (progress) => {
    callback(progress)
  })
  return result
})

And that's it! Also generate the d.ts files and move quickly to the client.


const resultVideo = await client.processVideo(video, (progress: number) => {
  console.log(`Progress: ${progress}`)
})

console.log(`Target video: ${resultVideo}`)