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 🙏

© 2026 – Pkg Stats / Ryan Hefner

fhem-client

v0.1.9

Published

A small Promise-based client for executing FHEM commands via FHEMWEB, supporting SSL, Basic Auth and CSRF Token.

Downloads

32

Readme

A small Promise-based client for executing FHEM commands via FHEMWEB, supporting SSL, Basic Auth and CSRF Token.
Uses Node.js http or https module, depending on the protocol specified in the URL; no further dependencies.

It provides the methods execCmd, execPerlCode and callFn to interact with FHEM.
See the full documentation for details.

Changelog

  • 0.1.9: Fixed tsc error "Cannot find module 'src/logger-iface' or its corresponding type declarations" when compiling a project that imports fhem-client.
  • 0.1.8: FhemClient.callFn now accepts boolean args.
  • 0.1.4:
    • Retry on error via
      • Property Options.retryIntervals of options param of FhemClient.constructor.
      • Property FhemClient.expirationPeriod
    • Specify agent options via property Options.agentOptions of options param of FhemClient.constructor.
    • Uses the same socket for each request.
    • Type definitions (.d.ts) included.
    • Completely rewritten in TypeScript, targeting ES2020.
  • 0.1.2: Specify request options for http[s].get via property Options.getOptions of options param of FhemClient.constructor. Especially useful to set a request timeout. There is a built-in timeout, but that's pretty long. FYI: Setting RequestOptions.timeout merely generates an event when the specified time has elapsed, but we actually abort the request.
  • 0.1.1: Added specific error codes instead of just 'EFHEMCL'.

Example

Import

TypeScript

import FhemClient = require('fhem-client');

JavaScript

const FhemClient = require('fhem-client');

Usage

const fhemClient = new FhemClient(
    {
        url: 'https://localhost:8083/fhem',
        username: 'thatsme',
        password: 'topsecret',
        getOptions: { timeout: 2000 }
    }
);

fhemClient.expirationPeriod = 20000;

async function example()
{
	await fhemClient.execCmd('get hub currentActivity')
		.then(
			result => console.log('Current activity:', result),
			// Like below, but in plain JS.
			// You may also write it like this in TS with the following directive for @typescript-eslint, in case you are using it:
			// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/restrict-template-expressions
			e => console.log(`Error: Message: ${e.message}, code: ${e.code}`)
		);

	await fhemClient.execPerlCode('join("\n", map("Device: $_, type: $defs{$_}{TYPE}", keys %defs))')
		.then(
			(result: string) => console.log(`Your devices:\n${result}`),
			// This is correct TS code:
		// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
			(e: Error) => console.log(`Error: Message: ${e.message}, code: ${(e as any).code as string}`)
		);

	// Notify your companion device that your server application is shutting down
	// by calling its function 'serverEvent' with arguments <device hash>, 'ServerStateChanged', 'ShuttingDown'.
	await fhemClient.callFn('myDevice', 'serverEvent', true, false, 'ServerStateChanged', 'ShuttingDown');
}

void example()