Windows Core IoT – NodeJS on a Raspberry PI3

Running Windows IoT on a RPI3 is just fun.

To get started some of my previous posts here

Anyhow I wanted to run a webserver on the RPI3… I checked around and one of the most obvious is running NodeJS on a RPI3.

The main advantages are that is that NodeJS is cross platform supported and needs a small memory footprint.

Solution :

1 NodeJS-ChaKaCore

Here : //nodejs.org/en/download/


2. Create a folder on your RPI3

Once download create a connection to your RPI3 and create a folder, like NodeJS


3. After this open the Downloaded ZIP step 1.

    And copy the all the files to the C:\NodeJS on your RPI3, except the SDK folder.

image

4. Create a JavaScript to start the Webserver.

Save it as Server.js on the C:\NodeJS folder

image

var http = require('http');

http.createServer(function (req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Hello World\n');
}).listen(1337);

5. Open the RPI3 Firewall Access

netsh advfirewall firewall add rule name="Node.js" dir=in action=allow program="C:\NodeJS\node.exe" enable=yes 

6. Start the WebServer

image

.\node.exe .\Server.js 


6. Test the connection to your new RPI3 WebNerver

Open a local Browser and test the connection to your http://RPI3:1337

Installing NodeJS Add-on Packages / Modules

Packages or Modules are extensions for NodeJS, see here for more details.

After installation check the version like this :

image

.\npm -v

1. Use NMP to download the required Packages or Modules

I tried this using the PowerShell remote connection … but that did not work.

Solution is to install NodeJS on your Local PC and grab the Modules.

Example : upper-case package


image

Error : ‘node’ is not recognized as an internal or external command

image

Wen running into this error run the command below.

Solution  : SET PATH=C:\Nodejs;%PATH%

2. Copy to the RPI3 NodeJS\node_modules directory


image

3. modify the Server.js JavaScript

Example : module upper-case

image

Notice the extra line require(‘upper-case’)

var http = require('http');
var uc = require('upper-case');

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.write(uc("Hello World!"));
    res.end();
}).listen(1337);

4. Test the result

image

Notice the response is in capital letters !

Enjoy !

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: