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

electron-request-response

v1.0.3

Published

A package that makes it easy to handle request response across electron render processes and the main process

Downloads

2

Readme

electron-request-response

This package allows you to communicate with the main process or render processes via a rest like interface. This package can only be used as part of an Electron app, it is not designed to be used with just a Node server or in a browser.

Why not IPC?

The IPC mechanism in Electron is quite powerful, but also quite cumbersome. A rest like interface is much more friendly and also more familiar to most JavaScript developers.

Concepts

  • Host - either the main process (CONSTANTS.MAIN_PROCESS.HOST) or the name of any BrowserWindow which you have made addressable via the makeAddressable(name, browserWindow) method
  • Route - an addressable endpoint. You register these in either the main process for use with the main process host, or in BrowserWindow processes when calling methods in those BrowserWindow processes.

API docs

You can find the API documentation in the Wiki for this repo

Quick start

In the main process:

var router = require('electron-request-response/main');

// electron startup stuff omitted

app.on('ready', () => {
  firstWindow = new BrowserWindow({height: 700, width: 800, frame: true, resizeable: true});
  secondWindow = new BrowserWindow({height: 700, width: 800, frame: true, resizeable: true});

  router.makeAddressable('first-window', firstWindow);
  router.makeAddressable('second-window', secondWindow);

  // there's no need to make a host unaddressable, this will happen automatically when the window is closed.

  // do some other stuff
}

Somewhere in the first window JS files

var router = require('electron-request-response/render');

// do some stuff that makes us want to communiate with second-window

var msgObj = {
  any_fields_you_want: 'Hey did you get this?'
};

router.request('second-window', '/some/path', msgObj)
    .then((response) => {
      console.log(resoinse); // on any day but Wednesday will print "I got it!"
      console.log('Yay! My message was received!');
    })
    .catch(function (err) {
      console.log('Oh no! Something went wrong!');
      console.log(err); // on Wednesday will print "Go away, it's hump day"
    });

Somewhere in the second window JS files

var router = require('electron-request-response/render');

// register a route

router.registerRoute('/some/path', function (data, callback) {
  console.log(data.any_fields_you_want); // will log "Hey did you get this?
  var shouldError = (new Date()).getDay() === 3; // we don't work on hump day
  if (shouldError) {
    return callback('Go away, it\'s hump day', null); // we could also use an object as the error here...
  }
  return callback(null, 'I got it!');
});