<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ibukun Soremekun</title>
    <description>The latest articles on DEV Community by Ibukun Soremekun (@ibukunsoremekun).</description>
    <link>https://dev.to/ibukunsoremekun</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F347917%2F9a0e049d-8156-489c-ab17-dd31fbcfa8cd.jpeg</url>
      <title>DEV Community: Ibukun Soremekun</title>
      <link>https://dev.to/ibukunsoremekun</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ibukunsoremekun"/>
    <language>en</language>
    <item>
      <title>API Security Best Practices</title>
      <dc:creator>Ibukun Soremekun</dc:creator>
      <pubDate>Sat, 25 Mar 2023 14:33:44 +0000</pubDate>
      <link>https://dev.to/ibukunsoremekun/api-security-best-practices-1l4a</link>
      <guid>https://dev.to/ibukunsoremekun/api-security-best-practices-1l4a</guid>
      <description>&lt;p&gt;In today's interconnected digital world, Application Programming Interfaces (APIs) play a crucial role in enabling seamless integration between various software applications, services, and platforms. APIs act as a bridge between different systems, allowing them to communicate and exchange data in a secure and reliable manner. However, with the increased use of APIs, the need for robust API security practices has also become critical. In this article, we will explore the best practices for securing APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
To fully understand the content of this article, it is recommended that you have experience designing API endpoints and a fundamental understanding of HTTP and web protocols. This will help you to better understand the importance of implementing API security measures and the impact they have on the overall security of your system. However, even if you are relatively new to API design and web protocols, this article provides an informative and accessible overview of the best practices for securing APIs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API Security Best Practices&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authentication and Authorization&lt;/strong&gt;&lt;br&gt;
The first line of defense for securing APIs is authentication and authorization. APIs should only be accessible to authorized users, and a robust authentication mechanism should be implemented to verify the identity of a user. This can be achieved through various methods such as API keys, OAuth 2.0, and OpenID Connect. Once the user is authenticated, the API should also enforce proper authorization rules to ensure that only authorized users can access specific resources and perform specific actions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Secure Data Transmission&lt;/strong&gt;&lt;br&gt;
APIs should always transmit data securely using secure protocols such as HTTPS, SSL, or TLS. These protocols provide a secure channel for transmitting data over the network, preventing eavesdropping, interception, and tampering with data in transit. It is also essential to use strong encryption algorithms and implement secure key management practices to protect sensitive data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Rate Limiting and Throttling&lt;/strong&gt;&lt;br&gt;
APIs should be protected against rate-limiting attacks, where attackers attempt to overwhelm the system by sending an excessive number of requests. Rate limiting and throttling mechanisms can help prevent such attacks by limiting the number of requests per user or IP address. This helps ensure that the API's performance is not impacted and legitimate users are not impacted by denial-of-service attacks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Input Validation and Output Sanitization&lt;/strong&gt;&lt;br&gt;
APIs should validate and sanitize all user input to prevent injection attacks such as SQL injection, XSS, and other types of attacks. APIs should also sanitize output data to ensure that sensitive information is not inadvertently disclosed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Error Handling and Logging&lt;/strong&gt;&lt;br&gt;
APIs should have a robust error-handling mechanism in place that provides detailed error messages to developers and administrators. Error messages should not reveal sensitive information that attackers could exploit. APIs should also log all API requests and responses to detect and investigate suspicious activities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Regular Security Testing and Auditing&lt;/strong&gt;&lt;br&gt;
API security is an ongoing process that requires regular security testing and auditing. Security testing should be conducted during the development stage, and regular penetration testing should be conducted to identify vulnerabilities and potential security threats. Security auditing can also help identify areas where security can be improved and ensure that security policies and procedures are being followed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Access Control and Privileges&lt;/strong&gt;&lt;br&gt;
APIs and database access control lists should be built with the principle of least authority in mind. The Principle of Least Authority (POLA), also known as the Principle of Least Privilege, says that all users and processes in a system should be given only those permissions that they need to do their job—no more and no less.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Setting Standard Security HTTP Headers&lt;/strong&gt;&lt;br&gt;
Security HTTP headers are a set of headers that enhance the security of web applications and APIs by providing additional security controls. These are some of the standard security HTTP headers that should be set to improve the security of APIs; Strict-Transport-Security (HSTS) Header, X-XSS-Protection Header, X-Content-Type-Options, X-Frame-Options, Content-Security-Policy. There are some middleware plugins like helmet (Nodejs) that help to automatically include these headers in every HTTP Request. By setting these standard security HTTP headers, you can improve the security of  APIs and protect against common web application attacks. It is essential to ensure that these headers are set correctly and are kept up to date to protect against emerging security threats.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The increase of API-related security threats in recent years has prompted the Open Web Application Security Project (OWASP) to release the &lt;a href="https://owasp.org/www-project-api-security"&gt;API Security Top 10&lt;/a&gt; , which is considered to be an authoritative baseline for secure web applications. &lt;br&gt;
By following the best practices discussed in this article, you can create secure and reliable APIs that protect against a range of security threats, including those outlined in the OWASP API Security Top 10.&lt;br&gt;
While no system can be entirely secure, these best practices can help you reduce the risk of attacks and protect data, applications, and services. As the threat landscape continues to evolve, it is essential to stay up to date with the latest security trends and continue to enhance API security measures.&lt;/p&gt;

</description>
      <category>api</category>
      <category>security</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Authentication: Token Based Auth vs. Session Based Auth</title>
      <dc:creator>Ibukun Soremekun</dc:creator>
      <pubDate>Thu, 23 Mar 2023 17:48:17 +0000</pubDate>
      <link>https://dev.to/ibukunsoremekun/authentication-token-based-auth-vs-session-based-auth-f88</link>
      <guid>https://dev.to/ibukunsoremekun/authentication-token-based-auth-vs-session-based-auth-f88</guid>
      <description>&lt;p&gt;Authentication is a crucial aspect of web application security that ensures the privacy and security of sensitive information. It is a process of verifying the identity of individuals, entities, or websites trying to access private information. &lt;/p&gt;

&lt;p&gt;Generally, this is done by requesting a username or ID along with one or more private pieces of information known only to the user. Inadequate authentication measures can expose sensitive information, increasing the risk of identity theft, data breaches, and other security threats.&lt;/p&gt;

&lt;p&gt;In modern web applications, users frequently need to verify their credentials to perform various actions or access protected resources. &lt;/p&gt;

&lt;p&gt;However, this can be a tedious and time-consuming process, leading to a poor user experience. To address this challenge, web applications offer users the option to log in once, allowing the system to remember the user's credentials for future use. &lt;/p&gt;

&lt;p&gt;This way, users can securely and seamlessly access protected resources without constant authentication, improving both the user experience and the security of the web application.&lt;/p&gt;

&lt;p&gt;Below we’ll look at two primary authentication methods for achieving secure access to protected resources without constant authentication: SessionBased Authentication and Token Based Authentication. We’ll cover how each is used and their pros and cons.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Session Based Authentication:&lt;/strong&gt;&lt;br&gt;
Session-based authentication is a method of user authentication used in web applications where the user's credentials are verified once, and a session is established for the duration of their interaction with the application.&lt;/p&gt;

&lt;p&gt;Once a user logs in and their credentials are verified, the system generates a session token or cookie, which is stored in the user's browser. This token is then sent with each subsequent request, allowing the system to identify the user and grant access to protected resources without the need for constant authentication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Token Based Authentication:&lt;/strong&gt;&lt;br&gt;
Token-based authentication is a method of user authentication used in web applications where a user's identity is verified using a unique token rather than traditional username/password credentials.&lt;/p&gt;

&lt;p&gt;When a user logs in, the application's server verifies their credentials and generates a unique token (also known as a bearer token or access token). The token is then sent to the user's browser, which stores it in local storage or a cookie. Subsequent requests from the user's browser include the token, allowing the server to identify the user and retrieve their user data.&lt;/p&gt;

&lt;p&gt;During the user's session, the token is used to authenticate the user and authorize them to access protected resources or perform actions on the application. Each time the user makes a request to the server, the token is checked to ensure that it is valid and authorized to perform the requested action.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Session Based Authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Simple and easy to implement: Session-based authentication is relatively easy to set up and implement, making it a popular choice for many web applications.&lt;/li&gt;
&lt;li&gt;Allows for complex authorization: Sessions can be used to store user data and permissions, allowing for more complex authorization schemes than simple username/password authentication.&lt;/li&gt;
&lt;li&gt;Automatic expiration: Sessions can be set to automatically expire after a set period of inactivity, helping to improve security and mitigate the risk of unauthorized access.&lt;/li&gt;
&lt;li&gt;Scalable: Session-based authentication can be easily scaled to support large numbers of users and sessions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Requires server-side storage: Session-based authentication requires server-side storage of session data, which can be resource-intensive and costly to implement at scale.&lt;/li&gt;
&lt;li&gt;Vulnerable to attacks: Session IDs can be stolen through various attacks, such as session hijacking or cross-site scripting (XSS), allowing attackers to impersonate the user and gain unauthorized access to sensitive data.&lt;/li&gt;
&lt;li&gt;Limited to single server: Sessions are typically stored in memory on a single server, making it difficult to scale across multiple servers or data centers.&lt;/li&gt;
&lt;li&gt;Requires cookies: Session-based authentication requires the use of cookies to store session IDs, which can be disabled or blocked by users, leading to usability issues.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Security concerns and possible solutions:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There are several common security concerns associated with session-based authentication:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Session hijacking: If a malicious user is able to obtain a user's session ID, they can use it to access protected resources as if they were the user. To prevent this, it is important to use secure session storage and transmission mechanisms, such as HTTPS and encryption.&lt;br&gt;
Set the "SameSite" attribute on HTTP headers to "Strict" or "Lax"; this ensures that the session cookie will only be sent with requests that originate from the same site as the web application. This prevents attackers from tricking a user into unknowingly sending a request with the user's session cookie to a different website, which could result in unauthorized actions being performed on behalf of the user.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cross-site scripting (XSS) attacks: Session-based authentication is vulnerable to XSS attacks, in which a malicious script is injected into a web page and executed by the victim's browser, allowing an attacker to steal the user's session ID or other sensitive information. To prevent this, it is important to use input validation and output encoding to prevent the injection of malicious scripts.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Session expiration: If a session does not expire or is set to expire after a very long time, a stolen session ID could be used by an attacker indefinitely. It is important to set an appropriate expiration time for sessions and implement mechanisms for renewing or revoking them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Server-side vulnerabilities: Session-based authentication does not protect against server-side vulnerabilities, such as SQL injection or file inclusion attacks. It is important to implement other security measures, such as input validation and output encoding, to prevent these types of attacks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Man-in-the-middle (MITM) attacks: Session-based authentication is vulnerable to MITM attacks, in which an attacker intercepts the communication between the client and server and can potentially steal the user's session ID or other sensitive information. To prevent this, it is important to use secure communication protocols, such as HTTPS.&lt;br&gt;
Set the "Secure" attribute on HTTP header to "true"; this ensures that the session cookie is only sent over encrypted connections (i.e., HTTPS). This prevents attackers from intercepting the session cookie while it is in transit and using it to impersonate the user.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Token Based Authentication&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pros:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stateless: Token-based authentication is stateless, meaning that the server does not need to store any session data. This makes it easier to scale across multiple servers or data centers.&lt;/li&gt;
&lt;li&gt;Scalable: Token-based authentication can be easily scaled to support large numbers of users and sessions.&lt;/li&gt;
&lt;li&gt;Better security: Tokens are generally more secure than session IDs since they can be cryptographically signed and verified to prevent tampering or forging.&lt;/li&gt;
&lt;li&gt;Flexibility: Tokens can be used for more than just authentication, such as for authorization and API access control.&lt;/li&gt;
&lt;li&gt;Cross-domain support: Tokens can be shared across multiple domains or subdomains, making it easier to implement single sign-on (SSO) across multiple web applications.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Cons:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Complex implementation: Token-based authentication is more complex to implement than session-based authentication since it requires the generation, signing, and verification of tokens.&lt;/li&gt;
&lt;li&gt;Token revocation: Tokens are typically valid for a longer period of time than sessions, which means they may need to be revoked in the event of a security breach or user logout. This can be challenging to implement and manage.&lt;/li&gt;
&lt;li&gt;Potential for token theft: Tokens can be stolen through various attacks, such as cross-site scripting (XSS) or interception of network traffic, which can allow attackers to impersonate the user and gain unauthorized access to sensitive data.&lt;/li&gt;
&lt;li&gt;User experience: Tokens are typically stored in local storage or cookies, which can be cleared or deleted by the user, leading to usability issues.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Security concerns and possible solutions&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Token leakage: If a malicious user is able to obtain a user's authentication token, they can use it to access protected resources as if they were the user. &lt;br&gt;
This can be resolved by implementing token revocation and securely handling saving tokens from the client in cookies and setting the HttpOnly attribute to true to prevent access to the cookie value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Token expiration: If a token does not expire or is set to expire after a very long time, a stolen or leaked token could be used by an attacker indefinitely. It is important to set an appropriate expiration time for tokens and implement mechanisms for renewing or revoking them.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Cross-site request forgery (CSRF) attacks: Token-based authentication is vulnerable to CSRF attacks, in which a malicious website tricks a user's browser into making a request to a protected resource on the user's behalf, using the user's authentication token. To prevent this, it is important to use anti-CSRF tokens, such as the SameSite cookie attribute or CSRF tokens.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Server-side vulnerabilities: Token-based authentication does not protect against server-side vulnerabilities, such as SQL injection or file inclusion attacks. It is important to implement other security measures, such as input validation and output encoding, to prevent these types of attacks.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Token revocation: If a user's authentication token is compromised or if the user's account is revoked or deleted, it is important to have a mechanism for revoking the token so that it cannot be used to access protected resources. This can be achieved through token blacklisting or other revocation mechanisms.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Choosing between session-based and token-based authentication depends on the specific requirements and use case. However, a hybrid approach can provide flexibility and increased security. &lt;/p&gt;

&lt;p&gt;Hybrid authentication combines the benefits of both systems by creating a secure token and session that is stored in a centralized storage like Redis. &lt;/p&gt;

&lt;p&gt;This approach also allows for easy revocation of tokens and setting session expiration. By utilizing the strengths of both session-based and token-based authentication, developers can create a more robust and secure application.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>discuss</category>
      <category>security</category>
      <category>api</category>
    </item>
    <item>
      <title>How To Build A Project Starter Template CLI Tool with NodeJs</title>
      <dc:creator>Ibukun Soremekun</dc:creator>
      <pubDate>Mon, 20 Mar 2023 17:22:15 +0000</pubDate>
      <link>https://dev.to/ibukunsoremekun/how-to-build-a-project-templates-cli-tool-with-nodejs-4jbl</link>
      <guid>https://dev.to/ibukunsoremekun/how-to-build-a-project-templates-cli-tool-with-nodejs-4jbl</guid>
      <description>&lt;p&gt;Starting a new software project can be a time-consuming and repetitive process. Developers often need to create a project structure and include various configuration files and dependencies to get the project running. These requirements are typically referred to as boilerplate code and can be reused across projects. While many frameworks offer CLI  commands to simplify the process of starting a project, they may not cover every use case.&lt;/p&gt;

&lt;p&gt;For instance, developers may need to reuse previously written code, such as linting configurations, database configurations, and related code snippets. Repeating these tasks for every project can be stressful and error-prone. One way to streamline the process is to create a CLI tool that generates project starters and code snippets based on specific needs.&lt;/p&gt;

&lt;p&gt;In this article, we will explore how to build a project starter template CLI using Nodejs, readline-sync, colors, and fs-extra. By the end of this article, you should be able to create your own project template generator CLI tool with Nodejs, so let's get started.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;br&gt;
Before you begin, you should be familiar with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NodeJS&lt;/li&gt;
&lt;li&gt;JavaScript &lt;/li&gt;
&lt;li&gt;NPM&lt;/li&gt;
&lt;li&gt;Basic Linux command line&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Let’s Get Started&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's dive into building a Nodejs project starter template CLI. To get started, kindly follow these steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a folder called &lt;code&gt;nodejs-project-cli&lt;/code&gt;.Then open the folder  in the terminal and run &lt;code&gt;npm init -y&lt;/code&gt; to create a new Node.js project with default options.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr6iavq14k1fl51nef2hm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr6iavq14k1fl51nef2hm.png" alt="npm init" width="800" height="393"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Install the necessary dependencies by running &lt;code&gt;npm install colors readline-sync fs-extra –save&lt;/code&gt; in the terminal. This will install the plugins needed for our project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open the project folder in your favorite text editor, and create a folder called "templates" in the root directory. This folder will hold all the projects you would like to generate with the CLI tool we are building.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a folder named &lt;code&gt;simple-express-app&lt;/code&gt; inside the "templates" folder.This folder will hold all the files required to setup a simple express app. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Now go ahead and create a file named &lt;code&gt;index.js&lt;/code&gt; add the code snippet provided below. The first line of the script is called a shebang and informs the shell about the interpreter to be used when executing the code on the terminal.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The code snippet uses the readline-sync plugin to prompt the user for input and the fs-extra plugin to manipulate the file system. It then checks if the templates folder is empty before prompting the user to select a template. Once a template is selected, the script prompts the user for a project name, confirms the project name, and then copies the selected template to the new directory.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env node
require('colors')
const readLineSync = require("readline-sync")
const path = require('path')
const fse = require('fs-extra')

const NO_CHOICE_MADE = -1
const CURR_DIR = process.cwd();
const templatesDir =  path.join(__dirname,'template')
const templates = fse.readdirSync(templatesDir)

if (!templates.length) {
   console.log('no template to choose from , templates folder is empty');
   process.exit(0)
}  

const index = readLineSync.keyInSelect(templates)

if (index === NO_CHOICE_MADE) {
   process.exit(0);
}

const projectName = readLineSync.question('What is the name of your project? ', {
   limit: input =&amp;gt; input.trim().length &amp;gt; 0,
   limitMessage: 'The project has to have a name, try again'
});

const confirmCreateDirectory = readLineSync.keyInYN(`You entered '${projectName}', create directory with this name?`);

if (confirmCreateDirectory) {
   const template = templates[index];
   const source = path.join(templatesDir, template);
   const destination = path.join(CURR_DIR, projectName);
   fse.copy(source, destination)
     .then(() =&amp;gt; console.log(`Successfully created ${destination}`.green))
     .catch(err =&amp;gt; console.error(err));
 } else {
   console.log('Aborted creating a new template');
 }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Now that we have set up everything, it's time to add the required starter files into the "simple-express-app" folder inside the "templates" folder. You can add more folders based on the number of starter template files you want. Once this is done, let's run the app and see how it looks. Open the terminal and type in &lt;code&gt;node index.js&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1irus6l9jq5pxjwnbcwt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1irus6l9jq5pxjwnbcwt.png" alt="test cli tool" width="800" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The app runs well at this point, but we don't want to have to navigate to the project before we can run our CLI. We need to make sure our project is set up to run as a bash script and installed globally so that it can be run as a command anywhere in the terminal.&lt;/p&gt;

&lt;p&gt;To do this, add the following snippet to the "package.json" file. The "bin" key helps to register "generateproject" as a command on the terminal as seen below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"bin": {
   "generateproject": "./index.js"
 },
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft4y029id8plhh8whz6i2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft4y029id8plhh8whz6i2.png" alt="package.json" width="800" height="464"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Finally, we need to install our CLI tool globally. Open the project folder in the terminal and run &lt;code&gt;sudo npm link&lt;/code&gt; or &lt;code&gt;sudo npm install&lt;/code&gt;. This installs the tool globally and makes it accessible through the &lt;code&gt;generateproject&lt;/code&gt; command.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, let's test out our CLI. Open your terminal anywhere on your machine and run the command &lt;code&gt;generateproject&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09mhjkdhmdxm3njn3zxm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F09mhjkdhmdxm3njn3zxm.png" alt="final cli test" width="800" height="524"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can add more template boilerplate code to the "templates" folder just like we did for "simple-express-app" and generate them on any new project you're working on. You can also uninstall the tool by running the command &lt;code&gt;sudo npm unlink&lt;/code&gt; or &lt;code&gt;sudo npm uninstall&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Yay, you made it! You have successfully created a powerful command-line interface that enables you to quickly create project starters with ease. While there are tools like this one with much more functionality, having your own tool is great. Nothing will satisfy your needs better than what’s written by you and for you.&lt;/p&gt;

</description>
      <category>node</category>
      <category>tooling</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
