Hello, blinky! background service

Create a blinky Node.js server that blinks an LED.


This sample only works with the Windows 10 IoT Core Anniversary Update (Build 14393) release with Visual Studio 2015 and does not currently work with any newer Windows releases or Visual Studio 2017. We are looking into adding Node.js support to UWP in a future release of Windows 10 IoT Core.

Set up your PC

  • Install Windows 10 with November update.
  • Install Visual Studio 2017.
  • Install the latest Node.js Tools for Windows IoT from here.

Set up your hardware

The setup for this sample is the same as the C# ‘Blinky’ sample.

Create a new Node.js (Windows Universal) project

Start Visual Studio 2017 and create a new project (File | New Project…). In the New Project dialog, navigate to Node.js as shown below (in the left pane in the dialog: Templates | JavaScript | Node.js). Use the Basic Node.js Web Server (Windows Universal) template.

When the project has been created, open up server.js and replace the existing code with the code shown below:

    var http = require('http');
    var uwp = require("uwp");
    var gpioController = Windows.Devices.Gpio.GpioController.getDefault();
    var pin = gpioController.openPin(5);
    var currentValue = Windows.Devices.Gpio.GpioPinValue.high;
    http.createServer(function (req, res) {
        if (currentValue == Windows.Devices.Gpio.GpioPinValue.high){
            currentValue = Windows.Devices.Gpio.GpioPinValue.low;
            currentValue = Windows.Devices.Gpio.GpioPinValue.high;
        res.writeHead(200, { 'Content-Type': 'text/plain' });
        res.end('LED value: ' + currentValue + '\n');

Here’s what the code above is doing:

  • GpioController.getDefault() is called to get the GPIO controller.
  • Then we attempt to open the pin by calling GpioController.openPin() with the LED pin value.
  • Once we have the pin, we set it to be off (high) by default using the GpioController.write() function.
  • When a request is made to the server, the value of the LED is checked and then set to the opposite of the current value. Doing this will toggle the LED on and off with each request made to the server.

Deploy the server to your Windows IoT Core device

  • Go to the Project menu and select ‘<Your project name> Properties’ (You could also right-click on the project node in solution explorer to access Properties). Enter the IP Address in the Remote Machine text box. If you’re building for Minnowboard Max, select x86 in the dropdown. If you’re building for Raspberry Pi 2 or 3, select ARM.

  • Now we’re ready to deploy to the remote Windows IoT Core device. Simply press F5 (or select Debug | Start Debugging) to start debugging the server.

  • When the server is running, open up a browser and enter the address http://<IP address of your device>:1337. Refreshing the page will turn toggle the on/off state of the LED. Note: If you are using Microsoft Edge or Google Chrome, two requests may be sent for each refresh which will keep the LED from changing.


Was this page helpful?
Additional feedback?
Thank you! We appreciate your feedback.
Follow us