• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Enable HTTP/2.0 in Node.Js

Written by Rahul, Updated on December 23, 2015

Node-http2 is a node module which provides client and server implementation of HTTP/2 protocol for nodejs application. This node API is very similar to node https module with extended support for HTTP/2.

Install Node.Js

You may skip this step if you have already installed node.js on your system. If you don’t have node.js on your system, use following commands to install it.

$ sudo apt-get install python-software-properties python g++ make
$ curl -sL https://deb.nodesource.com/setup_5.x | sudo -E bash -
$ sudo apt-get update
$ sudo apt-get install nodejs

Or you can also upgrade Node.js via npm.

Install Node-HTTP2 Module

node-http2 module is available under default npm library. So just execute following command to install it for your application.

$ npm install http2

Create Sample Node Server

Let’s create a sample node server with http/2 support. First create a self signed ssl certificate or get a valid SSL from authorized ssl providers.

$ openssl req -x509 -nodes -newkey rsa:2048 -keyout example.com.key -out example.com.crt

Now create http2-server.js file with following content.

1
2
3
4
5
6
7
8
9
10
var fs = require('fs');
var options = {
  key: fs.readFileSync('./example.com.key'),
  cert: fs.readFileSync('./example.com.crt')
};
 
require('http2').createServer(options, function(request, response) {
  response.end('Welcome HTTP/2.0');
  console.log("Server listening on: http://localhost:8000");
}).listen(8000);

Start Node Server

Let’s start the node.js server using following command. It will start a web server on port 8000 port on your system.

$ node http2-server.js

and access localhost on port 8000 like below.

Enable HTTP2 in Node.Js

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Ubuntu 20.04 5
  • How To Install Python 3.9 on Ubuntu 18.04 0
  • How to Use AppImage on Linux (Beginner Guide) 2
  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy