Close Menu
Soshace Digital Blog

    Subscribe to Updates

    Get The Latest News, Updates, And Amazing Offers

    What's Hot
    Interview

    Dmitrii Gorobets. What do you like most about being a developer?

    JavaScript

    Destructuring in JavaScript

    JavaScript

    Effective Strategies for Managing Project Dependencies

    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 / Node.js / Node.js Lessons / Node.js Lesson 1: Introduction and Modules
    Node.js

    Node.js Lesson 1: Introduction and Modules

    Mohammad Shad MirzaBy Mohammad Shad MirzaAugust 21, 2020Updated:September 23, 2020No Comments6 Mins Read
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Node.js Lesson 1: Introduction and Modules
    Node.js Lesson 1: Introduction and Modules
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link
    Node.js Lesson 1: Introduction and Modules
    Node.js Lesson 1: Introduction and Modules

    Hello everyone, this is the first lesson of the Nodejs course and we are going to cover the basics of Nodejs. We will also understand Modules in Nodejs and create one ourselves. Let’s start.

    Nodejs: Introduction

    JavaScript was meant for browsers but Nodejs allows us to run it on the server making our development much easier. Nodejs is JavaScript run-time environment. It means that we can create javascript standalone applications beyond the scope of the browser.

    A user usually interacts with the frontend of an application and JavaScript is great with building interactive websites. But before Nodsjs, we need a server to interact with Database and provide requested data to the website. For this purpose, we were either using PHP or Java more commonly.

    Nodejs helped us remove this barrier of language and allowed us to run JavaScript on the backend too. With Nodejs, developers don’t need to learn two different languages to code frontend and backend of an application. If you know JavaScript, you can build both. That’s one of the reasons for its remarkable adoption rate.

    Nodejs is used to create server-side applications. It is built upon Chrome’s V8 JavaScript engine which is why it’s really fast. It helps us easily build fast and scalable applications.

    Nodejs is non-blocking, it means that it can handle multiple requests at any moment. It doesn’t wait for the data to return. Instead, it adds the requests to a queue and starts serving more requests while the previous one completes.

    It is open-source and has around 1,372,861 packages contributed by the community at the time of writing this article. It means if you get stuck at any problem, there will probably be a package that can help you with that and you don’t have to code the solution yourself. We can help from these tested packages and speed up our development by building our application on top of it.

    We will follow this course by understanding different concepts in Nodejs and building an application. Let’s start with understanding Modules.

    What are Modules in Nodejs

    Modules help us bundle a set of functionality in a javascript library. In the Node.js module system, each file is treated as a separate module. We define functionality in the form of functions in a file and that file can be acquired using require(“Name of the module”) at any place. This allows us to reuse logic anywhere.

    Read More:  Finding the Best Way to Learn JavaScript

    Nodejs has a set of default modules already available to provide some basic functionality. Some of them are:

    • The Node.js events module.
    • The Node.js fs module.
    • The Node.js http module.
    • The Node.js os module.
    • The Node.js path module.

    For example:

    • http module allows Node.js to transfer data over the Hyper Text Transfer Protocol (HTTP).
    • fs stands for file system module and it allows us to work with the file system on our computer.

    We can also install any module from the gigantic library from the Node Package Manager (npm). Remember the 1,372,861 packages we talked about earlier? Those can be easily imported and used with the help of npm. We will learn about this in detail in coming lesson.

    How to Create a Module

    Let us create our first project with Nodejs. Our aim will be to get familiar with the concept of Modules and the Nodejs way of organizing our project. But before that, we need to have Nodejs set up on our machine.

    Step 1: Install Nodejs

    To install Node on your computer, go to https://nodejs.org and download the latest LTS version available. After installation is complete, go to terminal or command prompt and type node –version and make sure you can see the correct version you installed.
    If you see an error “command not found”, you will have to set up the PATH variable on macOS and Environment variable on Windows to locate node installed directory.

    When we install Node on our install, it also installs a command-line tool npm which stands for ‘Node Package Manager’. We will use this tool to initialize the project.

    Step 2: Initialize directory

    Now we have installed Nodejs and we are ready to create our first project.

    Create a directory and navigate to it via terminal.
    Type npm init, this will initialize the directory as a Nodejs project. Once the initialization is complete, you will see a package.json file created. Nodejs uses this file to track packages installed into your project.

    Read More:  PostgreSQL vs MySQL: Is There a Clear Winner?

    Step 3: Create entry file

    We are going to create an entry file for our project. Go ahead, create a file named index.js and add the code below:

    function User(name){
    this.name = name;
    }
    
    User.prototype.hello = function(who){
    console.log("Hello, " + who.name);
    };
    
    var tim = new User("Tim");
    var tom = new User("Tom");
    
    tim.hello(tom)

    Add a User object, which will create users then add a function hello. We will use this method to print out the name of the user with a greeting. Run it via console/terminal:

    node index.js

    If you can see the result on your terminal, it works. 👏🏼

    It’s a simple file but imagine if we want to use this functionality at multiple places. In that case, we can encapsulate this functionality into a module and export it. Let me show you how.

    Create a new folder user and add a file index.js with this code.

    function User(name){
    this.name = name;
    }
    
    User.prototype.hello = function(who){
    console.log("Hello, " + who.name);
    };
    
    console.log('user is required'); // to see when our module is required.
    exports.User = User;

    Now, require this module in index.js in root directory like this:

    const user = require('./user');
    
    var tim = new user.User('Tim');
    var tom = new user.User('Tom');
    tim.hello(tom);
    /**
     * console log:
     * user is required
     * Hello, Tom
     */

    You have just created your first module. 👏🏼

    Create a JSON file to store names

    Let us create our own JSON file that will keep information on our phrase in the console.log of a User.

    You will need to create a JSON file named en.json inside the user directory and add this:

    {
     "Hello": "Hi"
    }

    Then use it inside /user/index.js

    var phrases=require('./en');
    
    function User(name){
     this.name = name;
    }
    
    User.prototype.hello = function(who){
     console.log(phrases.who + ", " + who.name);
    };
    
    console.log("user is required!");
    
    exports.User = User;

    Directories can also be connected. In this case, Node.js searches files with this name, then it searches a file named user/en.json, and if it doesn’t find anything of these, it starts searching for a directory named user and there it will look for a file named index.js considering it a module.
    That’s it for today’s lesson. We will talk some more about Modules in the next lesson. Stay tuned.

    You can download lesson’s code from  the repository.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Mohammad Shad Mirza
    • X (Twitter)
    • LinkedIn

    JavaScript lover working on React Native and committed to simplifying code for beginners. Apart from coding and blogging, I like spending my time sketching or writing with a cup of tea.

    Related Posts

    Mastering REST APIs: Essential Techniques for Programmers

    December 18, 2024

    Crafting Interactive User Interfaces Using JavaScript Techniques

    December 17, 2024

    Effective Strategies for Utilizing Frameworks in Web Development

    December 16, 2024

    Comments are closed.

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo
    Don't Miss
    Events November 18, 2019

    Last Chance to Get Your Running Remote Early-Bird Ticket!

    We’re thrilled to announce that the early bird ticket sale for Running Remote in Austin is still on till December 15! 

    Node.js Lesson 8: Inheritance from Errors, Error

    October 28, 2020

    Vagrant Tutorial #part 2

    March 9, 2017

    Create simple POS with React.js, Node.js, and MongoDB #11: CRUD with Relation

    August 5, 2020

    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

    Effective Strategies to Secure Funding for Your Startup

    Startups November 24, 2024

    Balancing Enthusiasm: Effective Interview Strategies

    Interview December 1, 2024

    Step-by-Step Guide to Building a RESTful API Effectively

    Programming December 6, 2024

    Enim Facilisis Gravida Neque Convallis Cras Semper Auctor

    JavaScript January 27, 2020

    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
    Programming

    14. Уроки Node.js. Отладка скриптов. Часть 2.

    Programming

    PostgreSQL vs MySQL: Is There a Clear Winner?

    Programming

    22. Чат через long-polling, чтение POST. Pt.1.

    Most Popular

    Implementing Data Privacy Principles in Software Development

    Development

    6. Уроки Node.js. Util и Наследование

    Programming

    This Is Why Freelancing Is Not for Everyone | 5 Actual Lessons I Learned as a Freelancer

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

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