Skip to main content

Python print() Function

When you start learning Python, one of the first things you need to learn is how to display information on the screen. For example, you might want to display: A welcome message. Your name and age. The result of a mathematical calculation. Student marks and results. Information generated by a Python program. Python provides a built-in function called print() for displaying information. The print() function is one of the simplest and most frequently used functions in Python. It helps programmers display information while testing programs, solving problems, and developing applications. In this article, we will learn how to use print() with practical examples and their outputs. 1. What Is the print() Function in Python? The print() function is a built-in Python function that displays information in the output area, usually the terminal or console. Let's look at a simple example. print("Hello, World!") Output: Hello, World! In this example, Python displays the text Hello,...

Deploying PERN Stack Applications to Production

Introduction

In the previous article, we learned:

  • Context API

  • Redux Toolkit

  • Global state management

  • Authentication state

  • Redux store

  • Actions and reducers

Now it is time to move toward one of the most important stages of development:

Deployment

Deployment means making your application live on the internet so users can access it globally.

A deployed PERN stack application usually includes:

  • React frontend hosting

  • Node.js backend hosting

  • PostgreSQL cloud database

  • Domain configuration

  • Environment variables

  • Production optimization

In this article, we will learn:

  • What deployment is

  • Frontend deployment

  • Backend deployment

  • PostgreSQL cloud hosting

  • Environment variables

  • Production build process

  • Domain connection

  • Deployment best practices


What is Deployment?

Deployment means:

Publishing your application to a live server

Instead of running only on:

localhost

your app becomes accessible globally.

Example:

https://yourapp.com

Development vs Production

DevelopmentProduction
Local computerLive internet server
Testing environmentReal users
Debugging enabledOptimized performance

Architecture of a Deployed PERN App

React Frontend
      ↓
Hosting Platform
      ↓
Express Backend API
      ↓
Cloud PostgreSQL Database

Popular Hosting Platforms

PurposePlatform
FrontendVercel, Netlify
BackendRender, Railway
DatabaseNeon, Supabase

Frontend Deployment with Vercel

Vercel is one of the easiest platforms for React deployment.


Why Vercel is Popular

Vercel provides:

  • Fast deployment

  • Free hosting

  • Automatic SSL

  • GitHub integration


Creating Production Build

Inside React project:

npm run build

What Does build Do?

npm run build

creates an optimized production version of React application.


Build Folder

After build:

client/build

contains optimized frontend files.


Deploying React to Vercel

Steps

  1. Push project to GitHub

  2. Create Vercel account

  3. Import GitHub repository

  4. Click Deploy


GitHub Integration

GitHub automatically updates deployment whenever code changes.


Backend Deployment with Render

Render is commonly used for Express backend hosting.


Why Render is Good for Beginners

Render provides:

  • Free backend hosting

  • PostgreSQL support

  • Easy deployment

  • SSL certificates


Preparing Backend for Deployment

Install dotenv:

npm install dotenv

Using Environment Variables

Create:

.env

Example:

PORT=5000
DATABASE_URL=your_database_url
JWT_SECRET=mysecret

Accessing Environment Variables

require('dotenv').config();

const port = process.env.PORT;

Why Environment Variables are Important

Environment variables protect:

  • Database credentials

  • API keys

  • JWT secrets

Never expose secrets publicly.


Dynamic Port Setup

Wrong:

app.listen(5000)

Correct:

const PORT = process.env.PORT || 5000;

app.listen(PORT);

Production Backend Example

require('dotenv').config();

const express = require('express');

const app = express();

const PORT = process.env.PORT || 5000;

app.listen(PORT, () => {

    console.log(
        `Server running on ${PORT}`
    );
});

Cloud PostgreSQL Databases

Instead of local PostgreSQL, production apps use cloud databases.

Popular options:

  • Neon

  • Supabase

  • ElephantSQL


What is Neon?

Neon provides serverless PostgreSQL hosting.


Why Cloud Databases are Important

Cloud databases provide:

  • Backups

  • Scalability

  • Remote access

  • Reliability


Connecting Cloud Database

Example:

const pool = new Pool({

    connectionString:
    process.env.DATABASE_URL,

    ssl: {
        rejectUnauthorized: false
    }
});

Why SSL is Required

Production databases usually require:

SSL Encryption

for secure communication.


Handling CORS in Production

Frontend and backend are hosted on different domains.

Example:

Frontend:
https://myapp.vercel.app

Backend:
https://myapi.onrender.com

CORS Configuration

app.use(cors({

    origin:
    'https://myapp.vercel.app'
}));

Production API URL

During development:

http://localhost:5000

Production:

https://myapi.onrender.com

Using Environment Variables in React

Create:

.env

inside client folder.

Example:

REACT_APP_API_URL=https://myapi.onrender.com

Accessing React Environment Variables

process.env.REACT_APP_API_URL

Example API Request

fetch(

    `${process.env.REACT_APP_API_URL}/students`
);

Why Production Builds are Optimized

Production build:

  • Removes unnecessary files

  • Compresses JavaScript

  • Improves performance


What is Minification?

Minification means:

Removing unnecessary spaces and characters

to reduce file size.


Domain Names

Instead of:

myapp.vercel.app

you can use custom domains:

myapp.com

Popular Domain Providers

ProviderPurpose
NamecheapDomain purchase
GoDaddyDomain hosting
Google DomainsDomain management

Connecting Domain

Typical process:

  1. Buy domain

  2. Add DNS records

  3. Connect with hosting platform


What is DNS?

DNS stands for:

Domain Name System

It connects domain names with servers.


HTTPS and SSL

Production apps should always use:

HTTPS

Why HTTPS is Important

HTTPS provides:

  • Encryption

  • Security

  • Safe authentication

  • Secure payments


Deployment Workflow

Write Code
    ↓
Push to GitHub
    ↓
Hosting Platform Deploys
    ↓
Users Access Application

Continuous Deployment

Modern platforms automatically redeploy when:

  • New commits are pushed

  • GitHub updates

This is called:

Continuous Deployment

Logging in Production

Production apps should log:

  • Errors

  • Requests

  • Server crashes

Useful tools:

  • Morgan

  • Winston


Installing Morgan

npm install morgan

Example Morgan Setup

const morgan = require('morgan');

app.use(morgan('dev'));

Common Deployment Errors

CORS Errors

Fix using:

cors()

properly.


Environment Variables Not Working

Restart server after changing:

.env

Database Connection Failure

Check:

  • DATABASE_URL

  • SSL configuration

  • Network access


Build Errors

Always run:

npm run build

before deployment testing.


Best Practices

Use Separate Development and Production Databases

Never test directly on production database.


Protect Environment Variables

Never upload:

.env

to GitHub.


Optimize Images

Compressed images improve loading speed.


Monitor Backend Logs

Check logs regularly for:

  • Errors

  • Failed requests

  • Crashes


Real-World Deployment Architecture

Large applications use:

  • CDN networks

  • Load balancers

  • Docker containers

  • Kubernetes clusters

  • CI/CD pipelines


What is CI/CD?

CI/CD stands for:

Continuous Integration / Continuous Deployment

It automates:

  • Testing

  • Building

  • Deployment


Real-World Platforms Using Similar Architecture

Modern platforms like:

  • Netflix

  • Amazon

  • Facebook

  • Swiggy

  • Zomato

use scalable cloud deployment systems.


Conclusion

You have now learned how to deploy PERN stack applications to production.

You learned:

  • Frontend deployment

  • Backend hosting

  • Cloud databases

  • Environment variables

  • Production builds

  • HTTPS

  • Domains

  • CI/CD basics

Now your PERN stack applications are ready to be used by real users on the internet.

Comments

Popular posts from this blog

Understanding Comments in Java: A Beginner’s Guide

When learning Java programming, one of the first concepts you’ll come across is comments . Comments may not affect how a program runs, but they play a crucial role in making code more understandable, readable, and maintainable. Let’s dive deeper into what comments are, why they’re important, and the different types of comments in Java. What are Comments in Java? A comment in Java is a piece of text written within a program that is ignored by the compiler . In other words, comments are notes for humans, not instructions for machines. They help developers explain the purpose of code, describe logic, or temporarily disable certain lines of code without deleting them. Why are Comments Important? 📌 Readability – Comments make code easier to understand for you and others. 📌 Maintenance – When you revisit your code after months, comments remind you what you were doing. 📌 Collaboration – In team projects, comments explain code to fellow developers. 📌 Debugging – You c...

Java Program to Check Voting Eligibility

In this program, we’ll take the user’s age as input and check whether the person is eligible to vote or not. In India, the minimum age required to vote is 18 years . 💻 Program Code // Java Program to Check Voting Eligibility import java.util.Scanner; public class VotingEligibility { public static void main(String[] args) { // Create Scanner object to take input from user Scanner sc = new Scanner(System.in); // Ask user to enter age System.out.print("Enter your age: "); int age = sc.nextInt(); // Check eligibility if (age >= 18) { System.out.println("You are eligible to vote."); } else { System.out.println("You are not eligible to vote yet."); System.out.println("You can vote after " + (18 - age) + " year(s)."); } sc.close(); // Close the scanner } } 🧠 Explanation import java.util.Scanner; → Imp...

Java Program to Calculate Total Marks and Average of Five Subjects

💡 Program Explanation In this program: The user will input marks of five subjects . The program will calculate the total marks and average . It will then display both results clearly. 🧑‍💻 Java Code: // Java Program to Calculate Total Marks and Average of Five Subjects import java.util.Scanner; // Importing Scanner class for user input public class TotalAndAverage { public static void main(String[] args) { // Creating Scanner object to take input from user Scanner sc = new Scanner(System.in); // Declaring variables for five subjects double subject1, subject2, subject3, subject4, subject5; // Taking marks input for each subject System.out.print("Enter marks of Subject 1: "); subject1 = sc.nextDouble(); System.out.print("Enter marks of Subject 2: "); subject2 = sc.nextDouble(); System.out.print("Enter marks of Subject 3: "); subject3 = sc.nextDo...