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 🙏

© 2025 – Pkg Stats / Ryan Hefner

siyuan-background

v0.1.1

Published

A siyuan plugin background process manage framework.

Readme

Siyuan background

A siyuan plugin background process manage framework.

Support platform

Desktop (linux/windows/macos)

Functions

  • Read process.js and run it in background.
  • Keep alive when plugin reload or Siyuan frontend reload
  • Communication with plugin in foreground.
  • Logger to Console in foreground.

Usage (example)

Install the library with your favorite node package manager(npm/pnpm/yarn/...) in your plugin workspace.

npm install -D siyuan-background

Check the example plugin here: siyuan-plugin-background-test

Import this lib in your SiYuan plugin and call the ProcessManager to init your process.js.

Make sure you have an process.js in your plugin folder which is in Siyuan workspace/data/plugins/plugin-folder.

import { Plugin } from 'siyuan';
import { ProcessManager } from "siyuan-background";

export default class PluginSample extends Plugin {
  pm: any;
  async onload() {
    const pm = new ProcessManager(this);
    this.pm = pm;
    pm.init("electron", false).then((handler) => {
      // handler is the tool to connect with background process.
      handler.send("hello world"); // Using 'send' to send message to background process. MUST BE A STRING!!!
      handler.listen(console.log); // Get message sent from background process
      // **IMPORTANT** : Data exchange is inter-process communication, so you must manually serialize and deserialize the data.
      // For example: JSON.stringify and JSON.parse
      // Currently, only string-based data transmission is supported; serialized forms like Uint8Array are not supported.
    });
  }

  async onunload() {
    // you must call the unload method to stop background process, or it will not stop until close SiYuan.
    this.pm.unload();
  }
}

Here is an example of process.js

const { bridge, logger } = require("siyuan-background");
const fs = require('fs');

let number;
let server;
const httpport = 3001;

// write file to local system
const tmp = require('os').tmpdir();
const path = require('path');
const http = require("http");
const logFile = path.join(tmp, 'process.log');
const writeLog = (message) => {
    fs.appendFile(logFile, `[${new Date().toLocaleString()}] ${message}\n`, (err) => {
        err && console.error(err);
    });
}

// listen to connect event, it will be called when plugin run process.js first time or restore the connection to the exist process.
bridge.on("connect", () => {
  console.log('connected')
  logger.info("connected");
  writeLog("connected")
  bridge.send("hello, I am connected");

  // example: Create a http server when connected.
  if (!server) {
    server = http.createServer((req, res) => {
        res.statusCode = 200;
        res.setHeader("Content-Type", "text/plain;charset=utf-8");
        const log = `你好世界
PID:${process.pid} PPID: ${process.ppid}
number: ${number}
LogFile: ${logFile}
        `
        res.end(log);
        logger.info(log)
      });
    server.listen(httpport, () => {
        logger.info(`服务器运行在 http://:${httpport}/`);
    });
    }
});

// Listen to message from frontend plugin.
bridge.on("message", (data) => {
  logger.info("message:", data);
  writeLog(`message: ${data}`);
  number = data;
  if (data === "hello") {
    // send to frontend plugin.
    bridge.send("hello, too");
  } else {
    bridge.send("Recieved: " + data);
  }
});

// listen to the disconnect event, it will be called the SiYuan refresh the page.
bridge.on("disconnect", () => {
  logger.info("disconnect");
});

Plugin template using vite

If you are using the plugin template by siyuan which contain vite, you can try to add code to generate process.js.

You need to add a process.ts in src/ folder.

// vite.config.js

// add process.ts entry
    lib: {
            entry: [resolve(__dirname, "src/index.ts"), resolve(__dirname, 'src/process.ts')],
            fileName: "index",
            formats: ["cjs"],
    },

Changelog

  • v0.1.0: First version, migrate from siyuan-plugin-backend.