Skip to content

nibdo/ipc-express

 
 

Repository files navigation

ipc-express for electron

This library enables you to use the express framework in the mainthread of electron but without the http overhead.

Usage

Installation

npm i ipc-express

in your main.js file

const { ipcMain } = require('electron');
const express = require('express');
const { IpcServer } = require('ipc-express');

const expressApp = express();
const ipc = new IpcServer(ipcMain);

const someMiddleware = (req, res, next) => {
  next();
};
expressApp.use(someMiddleware);

expressApp.get('/test/:id', (req, res) => {
  res.send({
    params: req.params,
    query: req.query
  });
});


ipc.listen(expressApp);

In your frontend framework

import { IpcClient } from 'ipc-express';
const { ipcRenderer } = window.require('electron');

const ipc = new IpcClient(ipcRenderer);

  async componentDidMount() {
    const testId = 5;
    const { data } = await ipc.get(`/test/${testId}?test=testquery`);
    const { params, query } = data;
    console.log({ params, query })
  }

example

An example can be found in the example-app folder. To start the example-app:

cd example-app
npm run start:main
npm run start:renderer

contribute

  • fork this repo
  • npm i
  • make changes on new branch
  • update README
  • submit PR

Todo

  • extend the response object to an more express-like one

License

MIT

Copyright © 2019-Present, René Heinen. All rights reserved.

Changes in fork by nibdo

  • updated packages
  • modifications for handling responses in client
  • added methods and status in server
  • replaced ipcMain with ipcRenderer for server part to use it in different window

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 54.1%
  • TypeScript 32.1%
  • HTML 9.9%
  • CSS 3.9%