Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    CSS

    An in-depth guide on the CSS position property

    JavaScript

    React Lesson 10: Normalize Data with Immutable.js

    Consultation

    Best Service provides for Small Businesses

    Important Pages:
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Today's Picks:
    • Scaling Success: Monitoring Indexation of Programmatic SEO Content
    • Leveraging Influencers: Key Drivers in New Product Launches
    • How Privacy-First Marketing Will Transform the Industry Landscape
    • The Impact of Social Proof on Thought Leadership Marketing
    • Balancing Value-Driven Content and Promotional Messaging Strategies
    • Top Influencer Marketing Platforms to Explore in 2025
    • Emerging Trends in Marketing Automation and AI Tools for 2023
    • Strategies to Mitigate Duplicate Content in Programmatic SEO
    Wednesday, September 10
    Facebook X (Twitter) Instagram LinkedIn YouTube
    Soshace Digital Blog
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions
    Services
    • SaaS & Tech

      Maximizing Efficiency: How SaaS Lowers IT Infrastructure Costs

      August 27, 2025

      Navigating Tomorrow: Innovations Shaping the Future of SaaS

      August 27, 2025

      Maximizing Impact: Strategies for SaaS & Technology Marketing

      August 27, 2025
    • AI & Automation

      Enhancing Customer Feedback Analysis Through AI Innovations

      August 27, 2025

      Navigating the Impact of AI on SEO and Search Rankings

      August 27, 2025

      5 Automation Hacks Every Home Service Business Needs to Know

      May 3, 2025
    • Finance & Fintech

      Critical Missteps in Finance Marketing: What to Avoid

      August 27, 2025

      Analyzing Future Fintech Marketing Trends: Insights Ahead

      August 27, 2025

      Navigating the Complex Landscape of Finance and Fintech Marketing

      August 27, 2025
    • Legal & Compliance

      Exploring Thought Leadership’s Impact on Legal Marketing

      August 27, 2025

      Maximizing LinkedIn: Strategies for Legal and Compliance Marketing

      August 27, 2025

      Why Transparency Matters in Legal Advertising Practices

      August 27, 2025
    • Medical Marketing

      Enhancing Online Reputation Management in Hospitals: A Guide

      August 27, 2025

      Analyzing Emerging Trends in Health and Medical Marketing

      August 27, 2025

      Exploring Innovative Content Ideas for Wellness Blogs and Clinics

      August 27, 2025
    • E-commerce & Retail

      Strategic Seasonal Campaign Concepts for Online and Retail Markets

      August 27, 2025

      Emerging Trends in E-commerce and Retail Marketing Strategies

      August 27, 2025

      Maximizing Revenue: The Advantages of Affiliate Marketing for E-Commerce

      August 27, 2025
    • Influencer & Community

      Leveraging Influencers: Key Drivers in New Product Launches

      August 27, 2025

      Top Influencer Marketing Platforms to Explore in 2025

      August 27, 2025

      Key Strategies for Successful Influencer Partnership Negotiations

      August 27, 2025
    • Content & Leadership

      The Impact of Social Proof on Thought Leadership Marketing

      August 27, 2025

      Balancing Value-Driven Content and Promotional Messaging Strategies

      August 27, 2025

      Analyzing Storytelling’s Impact on Content Marketing Effectiveness

      August 27, 2025
    • SEO & Analytics

      Scaling Success: Monitoring Indexation of Programmatic SEO Content

      August 27, 2025

      Strategies to Mitigate Duplicate Content in Programmatic SEO

      August 27, 2025

      Effective Data Visualization Techniques for SEO Reporting

      August 27, 2025
    • Marketing Trends

      How Privacy-First Marketing Will Transform the Industry Landscape

      August 27, 2025

      Emerging Trends in Marketing Automation and AI Tools for 2023

      August 27, 2025

      Maximizing ROI: Key Trends in Paid Social Advertising

      August 27, 2025
    Soshace Digital Blog
    Blog / JavaScript / POS Tutorial / Create Simple POS With React, Node and MongoDB #4: Optimize App and Setup Deployment Workflow
    JavaScript

    Create Simple POS With React, Node and MongoDB #4: Optimize App and Setup Deployment Workflow

    Krissanawat KaewsanmuangBy Krissanawat KaewsanmuangFebruary 17, 2020Updated:May 26, 2024No Comments7 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Create Simple POS With React, Node and MongoDB #4: Optimize App and Setup Deployment Workflow
    Create Simple POS With React, Node and MongoDB #4: Optimize App and Setup Deployment Workflow
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    Create Simple POS With React, Node and MongoDB #4: Optimize App and Setup Deployment Workflow
    Create Simple POS With React, Node and MongoDB #4: Optimize App and Setup Deployment Workflow

    Defenition: POS – “Point of Sale”. At the point of sale, the merchant calculates the amount owed by the customer, indicates that amount, may prepare an invoice for the customer (which may be a cash register printout), and indicates the options for the customer to make payment.

    Before we add more features to our POS app, we need to optimize and restructure the app for better performance and clarity. Also, we will introduce a deployment pipeline so that when we commit code changes to GitHub, the app is automatically deployed to Heroku and Netlify.

    This is the list of the tasks we have to complete during this chapter.

    • [ ] separate backend and frontend
    • [ ] add environment variables to the backend
    • [ ] add environment variables to frontend
    • [ ] separate to individual route
    • [ ] setup auto-deployment of backend and frontend through Github

    So, let’s get started.

    [✔️ ] Separate backend and frontend

    We will remove the backend folder from the backend folder and move it outside. We also need to uninstall and reinstall the node modules.

    BASICPOS folders
    BASICPOS folders

    [✔️ ] Add an environment variable to the backend

    We will install the dotenv package to easily maintain keys and prevent API keys from being exposed to the outside world.

    npm install dotenv

    Import the package to index.js.

    require("dotenv").config({ path: __dirname + "/.env" });

    Create a .env file in the root directory and add our API key to the file in a key-value structure.

    MONGODB_URL=mongodb://localhost:27017/basicpos
    JWT_SECRET=qwertyuiopasdfghjklzxcvbnm123456
    SENDGRID_API_KEY=SG.EaHyDwHnQN6I4SXQKaNo6g

    Replace the keys we previously used in backend files using process.env.<key-name>.

    sgMail.setApiKey(
       process.env.SENDGRID_API_KEY
    );

    [✔️ ] Add an environment variable to frontend

    When using create react app, it is easier to maintain the environment variables. You can refer to the official document to see find out more details.

    1. Create .env file.
    2. Add a new variable to the .env file ( have prefix REACT_APP_ ). eg.REACT_APP_API_URL=http://localhost:8080/
    3. Replace the old static string.
      axios
      .post(process.env.REACT_APP_API_URL + "login", values)
    4. Restart the server.

    [✔️ ] Separate routes

    As our app expands and the number of routing endpoints increases, keeping all route access points in a single index.js file is not a good practice. Therefore, we reorganize our backend by moving all the routes to a new folder which has a main route access point. Then, we need to import these routes to the index.js file.

    Read More:  Advanced Node.Js: A Hands on Guide to Event Loop, Child Process and Worker Threads in Node.Js

    First, we will create a new api.js file and configure it as the main route access point.

    const express = require("express")
    const router = express.Router()
    require("./db")
    router.use(require("./api_auth"))
    // router.use(require("./api_product"))
    // router.use(require("./api_employee"))
    // router.use(require("./api_customer"))
    // router.use(require("./api_pos_machine"))
    // router.use(require("./api_branch"))
    module.exports = router

    The commented routes will be taken into use in the upcoming chapters.

    Now, create a file named api_auth.js inside the route older and move all the routes that relate to authentication from index.js into this. Here, replace the occurrences of ‘app’ with ‘router’.

    const express = require("express");
    const router = express.Router();
    const Users = require("./models/user_schema");
    const jwt = require("./jwt");
    const bcrypt = require("bcrypt");
    const formidable = require("formidable");
    const path = require("path");
    const fs = require("fs-extra");
    const jsonwebtoken = require("jsonwebtoken");
    const sgMail = require("@sendgrid/mail");
    sgMail.setApiKey(process.env.SENDGRID_API_KEY);
    router.post("/login", async (req, res) => {
    .......//colapse code
    });
    router.post("/register", async (req, res) => {
    .......//colapse code
    });
    router.get("/activation/:token", async (req, res) => {
     .......//colapse code
    });
    router.post("/profile", async (req, res) => {
    .......//colapse code
    });
    uploadImage = async (files, doc) => {
    .......//colapse code
    };
    router.put("/profile", async (req, res) => {
    .......//colapse code
    });
    router.post("/password/reset", async (req, res) => {
    .......//colapse code
    });
    router.put("/password/reset", async (req, res) => {
    .......//colapse code
    });
    module.exports = router;

    Import api.js to index.js.

    app.use("/api/v1", require("./api"))

    [✔️ ] Separate repository

    Creating a new repo
    Creating a new repo

    We need to create a new repository for the backend.

    Pushing the locally changed code to GitHub.
    Pushing the locally changed code to GitHub.

    Push the locally changed code to GitHub.

    [✔️ ] Deploy Node backend to Heroku

    Deploy Node backend to Heroku
    Deploy Node backend to Heroku
    Setting up automatic deployment from Github
    Setting up automatic deployment from Github

    Heroku is one of the top cloud providers that provide a simple way to deploy apps using Nodejs backend. Before deploying to Heroku, we need to build the app. This can be achieved by setting up automatic deployment from Github so that the whole process takes just one click.

    Set up auto-deploy from Github.
    Set up auto-deploy from Github.

    Set up auto-deploy from Github.

    Select the auto-deploy option to the auto-deployment.
    Select the auto-deploy option to the auto-deployment.

    Select the auto-deploy option to the auto-deployment.

    Setup env key in Heroku

    Adding all the environment variable keys into Heroku setting
    Adding all the environment variable keys into Heroku setting

    We need to add all the environment variable keys into Heroku setting

    We need to configure the app to use the Heroku port. Add the following code line to achieve this:process.env.PORT

    app.use("/api/v1",require("./api"))
    const port = process.env.PORT || 8080;
    app.listen(port, () => {console.log("Server is running... on port " + port);
    Heroku auto-deploy activity in the Activity tab
    Heroku auto-deploy activity in the Activity tab

    Now, every time you push the code to GitHub you will see Heroku auto-deploy activity in the Activity tab.

    Read More:  Exploring the Power of JavaScript Proxies and Reflect API

    Now try to open the app.

    Open the app
    Open the app
    Viewing the app log to figure out the problem
    Viewing the app log to figure out the problem

    We are getting a not found error. In Heroku, if something goes wrong, you can view the app log to figure out the problem.

    [✔️ ] Setup auto deployment from GitHub to Netlify

    We can use Heroku to host the frontend. But we have another better option to use Netlify. Netlify is a dedicated service for static hosting.

    Get the backend API url to be used in the frontend.

    Get the backend API url to be used in the frontend.
    Get the backend API url to be used in the frontend.
    Creating a new site -1
    Creating a new site -1
    Creating a new site -2
    Creating a new site -2
    Deploy settings
    Deploy settings
    Getting started
    Getting started

    Here, you can see deploy activities.

    Deploy activities
    Deploy activities

    Now we can open our live app hosted on Netlify.

    Opening app on Netlify
    Opening app on Netlify

    You can see a demo of the application here.

    Basic POS
    Web site created using create-react-appeager-hodgkin-9c4ccb.netlify.com

    Conclusion

    In this chapter, we learned how to setup environment variables on Node and React. Then we learned how to use the express router to organize the backend structure. Finally, we learned how to set up auto-deployment from Github to Heroku and Netlify.

    Git repos:

    https://github.com/krissnawat/basicpos-backend

    https://github.com/krissnawat/basicpos-frontend

    Credit

    Heroku Labs: Dyno Metadata
    Dyno metadata gives the dyno easy access to information about the app and environment. Examples of available dyno…devcenter.heroku.com
    The Beginner’s Guide to Netlify Continuous Deployment from Github for React Apps
    Continuous Deployment allows you to automatically update your development or production sites built with Netlify from…hackernoon.com
    Build environment variables
    Netlify environment variables are accessible during your build. This allows you to change behaviors based on deploy…docs.netlify.com
    Page Not Found on Netlify with React Router
    You might run into the following error after deploying a single page React site using React Router to Netlify. Page Not…sung.codes

    Previous lessons:

    Create simple POS with React, Node and MongoDB #3: setup E-mail pipeline with add activate on SignUp
    Create simple POS with React, Node and MongoDB #2: Auth state, Logout, Update Profile
    Create a simple POS with React, Node and MongoDB #1: Register and Login with JWT

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Krissanawat Kaewsanmuang
    • Website
    • X (Twitter)

    Developer Relation @instamobile.io

    Related Posts

    Streamlining Resource Allocation for Enhanced Project Success

    December 18, 2024

    Conducting Effective Post-Project Evaluations: A Guide

    December 16, 2024

    Strategies for Keeping Projects on Track and Meeting Deadlines

    December 10, 2024
    Leave A Reply Cancel Reply

    You must be logged in to post a comment.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    Podcasts April 11, 2019

    Engineering, Open-Source, and Interview-Heavy Web Development Podcasts — Part 2

    This is the second blog post on web development podcasts. Here, we’re featuring software engineering, open source, and interview-heavy podcasts.

    How to Make Remote Work More Effective?

    September 26, 2018

    How to Take Control of Your Tech Interview | Take Charge in Three Easy Steps

    March 22, 2019

    Ensuring Quality Hires: The Vital Role of Background Checks

    December 18, 2024

    Categories

    • AI & Automation
    • Angular
    • ASP.NET
    • AWS
    • B2B Leads
    • Beginners
    • Blogs
    • Business Growth
    • Case Studies
    • Comics
    • Consultation
    • Content & Leadership
    • CSS
    • Development
    • Django
    • E-commerce & Retail
    • Entrepreneurs
    • Entrepreneurship
    • Events
    • Express.js
    • Facebook Ads
    • Finance & Fintech
    • Flask
    • Flutter
    • Franchising
    • Funnel Strategy
    • Git
    • GraphQL
    • Home Services Marketing
    • Influencer & Community
    • Interview
    • Java
    • Java Spring
    • JavaScript
    • Job
    • Laravel
    • Lead Generation
    • Legal & Compliance
    • LinkedIn
    • Machine Learning
    • Marketing Trends
    • Medical Marketing
    • MSP Lead Generation
    • MSP Marketing
    • NestJS
    • Next.js
    • Node.js
    • Node.js Lessons
    • Paid Advertising
    • PHP
    • Podcasts
    • POS Tutorial
    • Programming
    • Programming
    • Python
    • React
    • React Lessons
    • React Native
    • React Native Lessons
    • Recruitment
    • Remote Job
    • SaaS & Tech
    • SEO & Analytics
    • Soshace
    • Startups
    • Swarm Intelligence
    • Tips
    • Trends
    • Vue
    • Wiki
    • WordPress
    Top Posts

    React Lesson 14: Redux Thunk Deep Dive

    JavaScript July 23, 2020

    React Lesson 6: CSS and Animation

    JavaScript January 4, 2020

    14. Node.js Lessons. Script Debugging pt 1.

    Programming September 30, 2016

    Why Using Node.js for Developing Web Applications Makes Perfect Sense

    JavaScript November 21, 2019

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    About Us
    About Us

    Soshace Digital delivers comprehensive web design and development solutions tailored to your business objectives. Your website will be meticulously designed and developed by our team of seasoned professionals, who combine creative expertise with technical excellence to transform your vision into a high-impact, user-centric digital experience that elevates your brand and drives measurable results.

    7901 4th St N, Suite 28690
    Saint Petersburg, FL 33702-4305
    Phone: 1(877)SOSHACE

    Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
    Our Picks
    Python

    Creating Real-Time API with Beautiful Soup and Django REST Framework

    B2B Leads

    Top Strategies for Effective B2B Lead Generation with Content

    Marketing Trends

    Maximizing ROI: Key Trends in Paid Social Advertising

    Most Popular

    Effective Data Visualization Techniques for SEO Reporting

    SEO & Analytics

    Getting started with Next.js

    JavaScript

    The Concept of Scope in JavaScript

    Beginners
    © 2025 Soshace Digital.
    • Home
    • About
    • Services
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

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