Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine.Node is designed to build scalable network applications. Latest version node.js ppa is maintaining on its official website.In this post, I'll work you through on how to get started with Node.js on a Debian 9 server.
Step 1 – Add Node.js PPA (personal package archive)
To work with a more recent version of Node.js, you can add the PPA maintained by NodeSource. This will have more up-to-date versions of Node.js than the official Debian repositories, We first need to install thecurl
if not
installed already, which you will use to access the PPAapt install curl
Step 2 – Install Node.js on Debian
Now that the pre request is out of our way , let's install the PPA in order to get access to its contents. Let's use curl
to retrieve the installation script for your preferred version, note that Latest LTS Version: 10.16.0 (includes npm 6.9.0) is recommended for most users, while the Latest Current Version is: 12.3.1 (includes npm 6.9.0) I will go with LTS.For LTS Release
curl -sL https://deb.nodesource.com/setup_10.x -o nodeppa_setup.sh
For Latest Release
curl -sL https://deb.nodesource.com/setup_12.x -o nodeppa_setup.sh
Once you have set up the script with desired version of node you can inspect the contents of this script using your preferred text editor or just run the script like this:-
bash nodeppa_setup.sh
After running the set up script the PPA will be added to your configuration and your local package cache will be updated automatically. And we get excellent instructions as what need to happen next so on with the show:
To install Node.js 10.x and npm run
apt-get install -y nodejs
Step 3 – Cehck Node.js & NPM Version
After completing installation check which version of Node.js you have installednode -v
v10.16.0
check the version of NPM as well:
npm -v
6.9.0
Step 4 – Install Necessary Tools For Node.js & NPM
You may also need development tools to build native addons:
apt-get install gcc g++ make
In order for some
npm
packages to work i.e (those that require compiling code from source), you will need to install the build-essential
packageapt install build-essential
Step 5 – Install The Yarn Package Manager
yarn is an advanced package management software for Node.js applications. You can install Yarn via the Debian package repository, first we need to import gpg key and configure the repository:curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
install yarn
apt-get update && apt-get install yarn
Check installed version
yarn -v
1.16.0
Step 6 – Creating Node.js Application For Testing
nano server.js
var http = require("http");
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8080);
// Console will print the message
console.log('Server running at http://192.168.0.247:8080/');
Srtart the server
node server.js
Server running at http://192.168.0.247:8080/
Now go to
http://192.168.0.247:8080/