Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Programming»Nodejs»How to Enable HTTP/2.0 in Node.Js

    How to Enable HTTP/2.0 in Node.Js

    By 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.

    Advertisement

    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

    Related Posts

    How to list all collections in MongoDB database

    How to Install Grunt on Ubuntu 22.04 & 20.04

    Running “npm start” with PM2

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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