GithubHelp home page GithubHelp logo

protocol-registry's Introduction

Protocol-registry

Registers protocol like myapp:// to open your nodejs app from browsers.

This is meant to be used in command-line tools and scripts, not in the browser.

Why?

  • Actively maintained.
  • Handles Cross Platform.
  • Supports WSL paths to Windows apps.

Install

$ npm install protocol-registry

Usage

const path = require('path');

const ProtocolRegistry = require('protocol-registry');

console.log('Registering...');
// Registers the Protocol
ProtocolRegistry.register({
    protocol: 'testproto', // set your app for testproto://**
    command: `node ${path.join(__dirname, './tester.js')}`, // this will be executed with a extra argument %url from which it was initiated
    override: true, // Use this with caution as it will destroy all previous Registrations on this protocol
    terminal: true // Use this to run your command inside a terminal
}).then(async () => {
    console.log('Successfully registered');
});

API

At present it supports :

register(options, cb(err))

Options are mentioned in the above example. If a valid callback is provided then it returns cb(err) Otherwise it returns a promise.

Example

const path = require('path');

const ProtocolRegistry = require('protocol-registry');

// Registers the Protocol
ProtocolRegistry.register({
    protocol: 'testproto',
    command: `node ${path.join(__dirname, './tester.js')}`,
    terminal: true
}).then(()=>{
    // do something
}).catch((e)=>{
    // do something
})
// Above will run tester.js when testproto://** is called as 
// node .../tester.js testproto://** 
// you can further parse the url to run in different modes
// As overide is not passed true it will throw an error is protocol already exists

ProtocolRegistry.register({
    protocol: 'testproto',
    command: `node ${path.join(__dirname, './tester.js')}`,
    terminal: true
},(err)=>{
    if(err){
        // do something
    }
})
// Example with callback

ProtocolRegistry.register({
    protocol: 'testproto',
    command: `node ${path.join(__dirname, './tester.js')}`,
    terminal: false // Terminal is set to false
},(err)=>{
    if(err){
        // do something
    }
})
// The above code will run your command in background
// You wont be able to see any logs
// But if your program launches any UI / webpage / file will be visible

checkifExists(protocol)

Checks if the provided protocol already exists or not. Returns a Promise which resolves in true or false.

Example

const path = require('path');

const ProtocolRegistry = require('protocol-registry');

// Registers the Protocol
ProtocolRegistry.checkifExists('testproto').then((res)=>{
    console.log(res) // true or false
    // do something
}).catch((e)=>{
    // do something
})
// Above snippet will check it already some app uses the given protocol or not

Supported platforms

  • Windows - OS - Supported
  • linux - OS - Supported
  • MacOS - OS - Work in progress - Not supported yet.

Contributors:

Credits goes to these people: ✨

protocol-registry's People

Contributors

shubham-kumar-2000 avatar san-saha avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.