How to create Module In Magento 2

Steps to create a new module in Magento 2

Create the folder of the module

The module name is defined as YourVendorName_YourModuleName. The first part defines the vendor and the last part defines the module. Like: Magento_NewModuleTheOnlineHelper_NewModule. Follow the following pattern to create the folders.

app/code/VendorName/ModuleName

Create etc/module.xml

etc is a necessary folder and a module.xml file is used to add the module.

Directory

app/code/vendorName/ModuleName/etc/module.xml

Content for module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="VendorName_ModuleName" setup_version="1.0.0">
    </module>
</config>

Create registration.php file

Every module must have a registration.php file, that defines Magento how to determine the module.

Directory

app/code/vendorName/ModuleName/registration.php

Content for registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
	\Magento\Framework\Component\ComponentRegistrar::MODULE,
	'VendorName_ModuleName',
	__DIR__
);

Run the "setup:upgrade" 

After completing the basic setup for the module, run the "setup:upgrade" to active the new module 

  php bin/magento setup:upgrade

Check the module status

To check the module status, run the following command:

  php bin/magento module:status

If your module status is disabled, run the following command to enable the module:

php bin/magento module: enable VendorName_ModuleName

OR

You can also access the file to active/enable the module

app/etc/config.php

Here, you will see a list of modules. Just locate your module and set this:

...
  'VendorName_ModuleName' => 1, 
  ...

And run this command.

php bin/magento setup:upgrade

If you are looking for Magento Services, visit Magento Development Agency.