Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Programming»Nodejs»How to Enable HTTP/2.0 in Node.Js

    How to Enable HTTP/2.0 in Node.Js

    RahulBy RahulDecember 23, 20152 Mins Read

    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

    HTTP/2.0 HTTP2 NodeJs
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Upgrade CentOS 7.8 from CentOS 7.7-7.0
    Next Article How to Install Development Tools on CentOS, RHEL & Fedora

    Related Posts

    How To Install NVM on Ubuntu 22.04

    Updated:April 16, 20223 Mins Read

    How To Install NVM on Windows

    Updated:April 16, 20223 Mins Read

    How To Install Node.Js on Debian 11

    Updated:February 11, 20226 Mins Read

    How To Install NVM on Debian 11

    Updated:August 31, 20213 Mins Read

    How To Use Environment Variables in Node.js

    6 Mins Read

    How to Parse Command Line Arguments in Node.js

    5 Mins Read

    Leave A Reply Cancel Reply

    Recent Posts
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    • What is the /etc/nsswitch.conf file in Linux
    • How to Install Ionic Framework on Ubuntu 22.04
    • What is the /etc/hosts file in Linux
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.