Skip to main content

How to Install Latest Nodejs, NPM & Yarn on Debian


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 the curl if not installed already, which you will use to access the PPA
  
apt 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 installed

node -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 package

apt 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/

Popular posts from this blog

How To Install the Anaconda Python Distribution on Debian 9 And Running a public notebook server

Anaconda Distribution is an open-source package manager, environment manager and distribution of Python and R programming languages. With a collection of 1,000+ open source packages with free community support. Designed for data science and machine learning workflows, you can use it whether you are on Windows, macOS or Linux. The Anaconda distribution ships with the conda command-line package management utility. You can learn more about Anaconda and conda by reading the official Anaconda Documentation . Jupyter is a browser-based interpreter that allows you to interactively work with Python and R. Anaconda provides Jupyter as well. You can think of Jupyter as a digital notebook that gives you an ability to execute commands, take notes and draw charts.It’s primarily used by Data Scientists. But I find that very useful tool if you are learning Python or R. It’s basically the same as working on a shell but much better. The Jupyter notebook web application is based on a

How to create REST API using Django REST Framework

This post begins with already working project and app's, I found that there some few requirement's that my project needed to handle and the best option for those requirement's was to use the Django's  Rest Framework. The way that I will tackle this task is more specific to the needs of the project rather than a one to one how to..., that being said you can still follow along, the approach that I'm going to use is easy to follow since I'll be providing a lot of information a log the way for better understanding of the why and how.....this code is available on Github , enough with the alerts and on with the show. Note:  If you would want to mimic the exactly settings then you will need to enable user authentication on your project you can follow this link for details .  Start with the DRF (Django Rest Framework) installation pip3 install djangorestframework For our app to use DRF, we'll have to add rest_framework into our settings.py.   nan

django react app setting up the backend

On the previous article I demonstrated how we can use the generic views along with ModelSerializer classes to rapidly develop our REST APIs. Knowledge that you will need  in your career as full stack / backend developer, however think of this article as an extension to the previous one, equipped with what we already know about REST API we will step our game up and discuss about ViewSet, ModelViewset we will dig deep into the concepts of Routers which allow us to manage our api routes in a simple and sophisticated manner as well as helping to speed up building APIs even further. There for on part II of this article i'll work you through on how React application can consume this RESTful API. There for at the end of the day we will have a full stack web app, in short we strat our development at the backend then later on we move at the frontend... so are you excited and ready to take the challange? lets do this then..... you can get source code for the bakend on github Preparat