- Go to https://nodejs.org and look for the current version of node.js. At this moment, for me version
9.5.0
is the current version. - Open Terminal and Type
curl -sL https://deb.nodesource.com/setup_9.x | sudo -E bash -
- Note: in future if you see the current version 10.x.x then in the URL above replace setup_9.x with
setup_10.x
sudo apt-get install nodejs
sudo apt-get install npm
sudo npm i -g npm
- In order for some npm packages to work (such as those that require building from source), you will need to install the build-essentials package.
sudo apt-get install build-essential
- To install git on your Raspberry Pi, open terminal and Type:
sudo apt-get install git-core
git clone https://github.com/apal21/Raspberry-pi-LED-blink-node.js
cd Raspberry-pi-LED-blink-node.js
npm install
node index.js
ornpm run test
mkdir LED-blinking && cd LED-blinking
npm init --yes
nano index.js
and paste the content of this repo's index.js file.npm install onoff
node index.js
- In this code, I've used GPIO4 (pin #7)
- Change this according to your requirements.