What is PERN Stack?

This stack consists of PostgreSQL, Express, React and Node.js. Combining these technologies, one can build a full-stack web application with CRUD operations. Everyone must have heard about MERN Stack which is basically a JavaScript Stack for the deployment of full-stack web development and contains 4 technologies, namely: MongoDB, Express, React and Node.js. but PostgreSQL seems to be gaining more popularity because it offers wide support for NoSQL feature, transactional and standard compliant. It is written in C language.

What-is-PERN-Stack

Knowing about PERN Stack Components:

  1. PostgreSQL (Object-Relational Database)

    PostgreSQL is a powerful, open source object-relational database management system (ORDBMS) with an emphasis on extensibility and standards compliance that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads. PostgreSQL is ACID-compliant, transactional, that stores the data in the tabular format and uses constraints, triggers, roles, stored procedures and views as the core components.
    Why use PostgreSQL?

    • Free and open source.
    • Available in multiple languages.
    • Highly extensible.
    • Protects data integrity.
    • Builds fault-tolerant environments.
    • Robust access-control system
    • Supports international characters.
    • Apple uses PostgreSQL!

    Writing queries in PostgreSQL:



    • Creating students table
       CREATE TABLE students (id INT, name VARCHAR (100)); 
    • Inserting a record into students table
       INSERT INTO students VALUES (1, 'Geeks'); 
    • Reading records from the students table
       SELECT * FROM students; 


    • Updating records in students table
       UPDATE students SET name="GeeksforGeeks" WHERE id = 1; 

    • Deleting records from students table
       DELETE FROM students WHERE id = 1; 
  2. Express (Back-End Framework)
    It is a web application framework for Node.js. Being a free and open software, it is used for building web applications and specially APIs. Express provides a thin layer of fundamental web application features, without obscuring Node.js features that you already know.

    Why use Express?

    • Provides a robust set of features for both web and mobile applications
    • Makes back-end code easier and simpler to write.
    • Supports many middleware.
    • Minimal and Flexible web application framework.
    • Creating efficient and robust API is quick and easy.
    • Allows you to define an error handling middleware.

    How to use it?
    Create a new folder and cd into it using command line. Then type the following code to initialize a package.json file. Click Enter by accepting the default settings.

     npm init 


    Then write the following command to install express.

     npm i express --save 


    Write the following code in the index.js as a sample.

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    const express = require("express");
      
    const app = express();
      
    app.use((req, res) => { 
      console.log(req.headers); 
       
      res.setHeader('Content-Type', 'text/html'); 
      res.end('<html><body><h1>Hey there, Welcome to Geeks for Geeks!! </h1></body></html>'); 
      });
      
      
    app.listen(3000, function(){
        console.log("Server is running at port 3000");
    });

    chevron_right

    
    

    Then, write the following code in the command line

     node index.js 


    Then, open the localhost:3000 in the browser and you will see the following result

  3. React (Front-End Framework)
    React is basically a JavaScript library for building user interfaces. It is easy, efficient and painless way to create Interactive UIs. It is maintained by Facebook and a community of individual developers and companies. Design simple views for each state in your application, and React will efficiently update and render just the right components when your data changes and for this reason only, it is used for developing single-page application or mobile applications.

    Why use React?

    • Virtual DOM in ReactJS makes user experience better and developer’s work faster
    • It guarantees stable code.
    • React allows its components to be reused saving time and effort.
    • Provides high performance.
    • Provide the feature of Virtual DOM.
    • SEO friendly!

    How to use it?
    First of all, install the react app by using following code

     npm install create-react-app –global 

    After that, make a folder and cd into that folder using command line and create a new react app by using the following code:



     create-react-app app_name 

    After that, go into that folder and in src folder, you will see App.js file. Paste the following code in App.js

    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    function App () {
      return (
    <div> <h1> Welcome to Geeks for Geeks! </h1> </div>
      )
    }

    chevron_right

    
    


    Then, use the below code for running your application.

     npm start  


    Ultimately, you will get the following output:

  4. Node.js (JavaScript runtime environment)
    Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine for developing server-side and networking applications. Being an asynchronous event-driven JavaScript runtime, it is used to build fast and scalable network applications. Node.js is free and open source server environment that runs on many platforms.

    Why Node.js?

    • Provides event-driven and asynchronous features which makes it lightweight and efficient.
    • No buffering and thus, is very fast.
    • Highly Scalable.
    • Highly extensible.
    • Provides advantage of caching.
    • Handles thousands of concurrent connections with a single server.
    • Provides vast number of libraries.
    • How to use it?
      Make a folder and cd into that by the user command line and then, initialize the node.js application by running the following code

       npm init 

      Create a file named index.js and run the following code in that:

      filter_none

      edit
      close

      play_arrow

      link
      brightness_4
      code

      console.log("Hello, this is GeeksforGeeks")

      chevron_right

      
      

      Now execute the following command in command line:

       node index.js 

      After that, you will see the following output in your browser:

        Hello, this is GeeksforGeeks  



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

45


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.