Socket
Book a DemoInstallSign in
Socket

electron-server

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-server

Use Fastify inside an Electron app without consuming a port

latest
npmnpm
Version
0.2.0
Version published
Weekly downloads
10
-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

Electron Server

A super-fast and easy-to-use library to use Fastify, and it's ecosystem inside an Electron application without the need of exposing (and consuming) a port.

Use-cases

  • Running GraphQL in your Electron application.
  • Running Next.js using fastify-nextjs to create chrome://extensions like pages for your Electron app
  • Communication between main and renderer process using HTTP methods
  • Static file (assets) sharing between renderer process and the main process

Install

To install electron-server in an existing project as a dependency:

Install with npm:

npm i electron-server

Install with pnpm:

pnpm add electron-server

Example

// Require fastify and instantiate it.
const Fastify = require('fastify')
const server = Fastify({ ignoreTrailingSlash: true })
server.get('/hello-world', () => ({ hello: 'world' }))

// Require registerProtocol and call it on your root file.
const { registerProtocol } = require('electron-server')

// Register custom scheme to Electron
registerProtocol({
  scheme: 'my-scheme',
  server,
})

app.whenReady().then(() => {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
  });
  
  // Visit the custom scheme
  win.loadURL("my-protocol://hello-world");
});

Do you want to run the example? Head to the Playground.

Keywords

Electron.js

FAQs

Package last updated on 13 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts