Help with Node.js Code - "Error: Cannot find module 'lifx-api'"

Hello All,

I am new to all IOT and coding.
I am trying to us Node.js on a raspberrypi in order to control my lights.

  1. I have Node.js running.
  2. I have the code I need to execute.
  3. I got the LIFX API Toke.

But when I execute the code I get the following errors:

Error: Cannot find module 'lifx-api’
at Function.Module._resolveFilename (module.js:440:15)
at Function.Module._load (module.js:388:25)
at Module.require (module.js:468:17)
at require (internal/module.js:20:19)
at Object. (/home/pi/LIFX-Dash-Button/index.js:7:15)
at Module._compile (module.js:541:32)
at Object.Module._extensions…js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)

My assumption is that all these errors are related to the “Cannot find module ‘lifx-api’” Error I am getting.

How can I get this installed on my Raspberrypi? I am running Raspbian on it.

Thanks and best regards,


Maxi you will need to clarify a few things, where are you getting your API from ? If this is the LIFX release api it is years old and not applicable any more as LIFX no longer support them.
LIFX has documented the LAN API and made available the cloud HTTP API but anything else you have to source as 3rd party or develop yourself.

I have just solved the issue, I was executing “npm install” on the wrong directory and without Root Privileges (I am new to Linux and even newer for all this coding thing).

The problem I have now is that the Code is only controlling one light. I will need to figure this out.

Thanks a lot for the reply.



AFAIK LIFX has never released a Node.js library for controlling LIFX bulbs.

However I’m happy to answer questions around code and talking to LIFX bulbs, you just have to provide details of the problem, and what you have tried already.

I am trying to implement some kind of Physical Switch to my Lights, having to use the Phone all the time is not the best thing and I cannot use any of the Smart Switch on the Market, because they are all for 110 Volts and I line in Argentina, we use 220 Volts here.

First, I tried with FLIC Buttons:

  • They are working OK, but lag is an issue.
  • I need to have like a BT Hub, which I made with an old iPod I have.
  • The connection does not always work.

My Second thought was to get a Wi-Fi Smart Button, but I did not find any of these on the Market. What I found is the Amazon Dash Button, which with this code ( you can use to Toggle the Lights.

I managed to get it working but Lag is still an issue, because the program only works when the Button is connected to the network, and even thought the process is fast, it takes from 2 to 4 or even more seconds.
Only one light is working, I have not been able to figure this out yet, luckily for me, the Light the Button is controlling is one of the ones I would like to control. But I am not sure why the code is controlling only one of all my lights when I think the code is designed to control all the lights.

All the Above took me to my third option that is to make a Physical Switch with an ESP8266.
I am thinking on having it connected to the network all the time to avoid having any delay. I saw a video in which the guy used it as the Dash Button, but there was delay in the response also. That option will not work for me.

But my biggest issue is that I have never made any coding and I got to the point where it is too complex for me. I just started with Arduino a couple of weeks back and I feel like I am trying to Escalate too fast.

Thanks a lot for the replies.

You know what gets me, how many years has LIFX been out now and there is still not one single well designed affordable and safe light switch available. You would think by now LIFX would have a solution, Philips have them so what is taking LIFX so long.

If you are looking for a switch, and don’t feel up to building your own, check out companies like Control4 and HomeSeer. Both of these, and several others have support for LIFX bulbs already. They also support many many different switches, so you can find one suits you.

Daniel you validated my point.

  1. Homeseer only US dealers and you need to put in a system
  2. Control4 Same deal…
    I have the original bulbs and from what I can see the above needs the newer ones.

A simple light switch is all that is needed and LIFX has not acted on it.

Here is my node script to show device light numbers. Make sure you are using an up to date node version as I use ES6:

const fetch = require('node-fetch');
var LIFX_TOKEN = `Bearer ${process.env.LIFX_TOKEN}`;
var LIFX_HOST = '';

function toJSON(response) {
  return response.json();

function listLights() {
  var url =

  var request = new fetch.Request(url, {
    headers: {
      'Accept': '*/*',
      'Authorization': LIFX_TOKEN,
      'Accept-Encoding': 'gzip, deflate',
      'Content-Type': 'application/json'

    .then((e) => {
    .catch((e) => {
      console.log('error ' + e);