Nodejs Simple Website

Posted on

If Needed install Nodejs and npm by running the command

sudo apt-get install nodejs npm

Installation of each can be verified by typing

node -v
npm -v

Node installation can also be tested by typing


Install the npm package called http-server. The http-server package was created by the amazing IndexZero (aka Charlie Robbins). Navigate to directory

sudo npm install -g http-server

Change the directory to the /home/pi/Public directory to store and serve up public web files. Create file index.html and and insert test html.

cd /home/pi/Public
sudo touch index.html
sudo nano index.html

Welcome to my website!

Save and close index.html, verify the file exist in the directory then launch http-server

#Verify that the file exists
#Start Nodejs Web Server

Starting up http-server, serving ./
Available on:
Hit CTRL-C to stop the server

open webrowser and enter the IP address or http://localhost:8080 which should open website displaying “Welcome to my website!”

On a different computer on the same network the same webpage should be accessible by typing the http://[IP address]:8080 or http://[hostname]:8080