<?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: Sarthak Mahulikar</title>
    <description>The latest articles on DEV Community by Sarthak Mahulikar (@sarthak619).</description>
    <link>https://dev.to/sarthak619</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%2F1286490%2F6c075f23-cc91-40bb-b0d1-8be0c3bc8bd2.png</url>
      <title>DEV Community: Sarthak Mahulikar</title>
      <link>https://dev.to/sarthak619</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sarthak619"/>
    <language>en</language>
    <item>
      <title>Backend with Node JS : Installing and Creating NodeJS Server</title>
      <dc:creator>Sarthak Mahulikar</dc:creator>
      <pubDate>Wed, 29 Jan 2025 12:22:39 +0000</pubDate>
      <link>https://dev.to/sarthak619/backend-with-node-js-installing-and-creating-nodejs-server-29hj</link>
      <guid>https://dev.to/sarthak619/backend-with-node-js-installing-and-creating-nodejs-server-29hj</guid>
      <description>&lt;p&gt;This blog will give you brief information of how to Create server using Node.js, Express. Lets understand and go through every step of code and features.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up Node.js project
&lt;/h2&gt;

&lt;p&gt;Lets start with creating new project directory&lt;br&gt;
&lt;strong&gt;Step-I : Creating New Project Directory&lt;/strong&gt;&lt;br&gt;
Make a new directory for the project. For creating the new directory  open terminal at location where we want to create project folder. Now for creating folder use "&lt;strong&gt;mkdir&lt;/strong&gt;" command.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;mkdir your-project-name&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For opening the new directory use "&lt;strong&gt;cd&lt;/strong&gt;" command as follow&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;cd your-project-name&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Step-II: Establishing Node.js project&lt;/strong&gt; &lt;br&gt;
 For creating the Node.js project we need to initialize it. In order do this use "npm init" command in the directory of our project.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;npm init&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After using npm init command you will be prompted to enter the information about the project such as Name, Version, Description, Entry Point(Generally it is index.js), and more such options. We can provide our own info setting or else we can accept the default setting by pressing Enter.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fl8mn66rowstg07zrbzju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fl8mn66rowstg07zrbzju.png" alt="Image description" width="800" height="286"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the above step is completed a package.json file will be created in our project directory. All the information related to Project and Dependencies is included in the package.json file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-III: Setting up the file structure in project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fhoc4at8budue40d852ir.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fhoc4at8budue40d852ir.png" alt="Image description" width="694" height="615"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-IV: Installing express and dotenv&lt;/strong&gt;&lt;br&gt;
In our project we need Express to build single page application and web application. Express will provide the REST services like handling routes, requests and responses. Dotenv is basically used for loading the environment variables from a &lt;strong&gt;.env&lt;/strong&gt; file  into &lt;strong&gt;process.env&lt;/strong&gt; .It is also used for keeping your sensitive data like database credentials, API keys safe.&lt;/p&gt;

&lt;p&gt;For installing above packages use command below:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;npm install express dotenv cors&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After executing above command node_modules folder will be created in our project along with package-lock.json file.&lt;/p&gt;

&lt;p&gt;Before starting to code ensure which type of structure we want to use in package.json file from two options &lt;strong&gt;"commonjs"&lt;/strong&gt; or &lt;strong&gt;"module"&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.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%2Fdzkvi71os1mvc8knjt7j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fdzkvi71os1mvc8knjt7j.png" alt="Image description" width="800" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In our project we will use module as shown in above image &lt;strong&gt;"type":"module"&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Also we need to install nodemon dev-dependency. Nodemon is tool which automatically restart server after any update done in our nodejs code.   &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;npm install --save-dev nodemon&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;After running install command do change "scripts" as shown in image below&lt;br&gt;
&lt;a href="https://media2.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%2Fqf254l4185o8vcrffw8p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fqf254l4185o8vcrffw8p.png" alt="Image description" width="800" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-V : Creating And Starting Server&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating The Server&lt;/strong&gt;&lt;br&gt;
    The first we need to do is go to our &lt;strong&gt;app.js&lt;/strong&gt; file and import below packages which are required for creating server and CRUD operations.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Required packages 
import express from 'express' ;
import cors from 'cors';
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we will create server by using express().If we want to provide CORS_ORIGIN then we can provide it in .env file and then use it in configuration of cors. If we want to provide access for all origin then write &lt;strong&gt;CORS_ORIGIN=&lt;/strong&gt; *&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const app = express();
app.use(
    cors({
        origin: process.env.CORS_ORIGIN,
        credentials: true,
    })
);

app.use(express.json());
app.use(express.urlencoded({ extended: true, limit: '16kb' }));
app.use(express.static('public'));
export { app };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now go to &lt;strong&gt;index.js&lt;/strong&gt; file and write below code to start server on the port as defined in .env file or 3000.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { app } from './app.js';
import dotenv from 'dotenv';
dotenv.config({ path: './env' });
const port=process.env.PORT || 3000;
app.listen(port, () =&amp;gt; {
    console.log(`server is running on port ${port}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After adding above code go to the terminal and run below command to start server.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;npm run dev&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media2.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%2Fc6ummmedy7x82xgtvg5z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.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%2Fc6ummmedy7x82xgtvg5z.png" alt="Image description" width="800" height="194"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Conclusion:&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;These are the steps for setting up project in Nodejs and starting backend server. &lt;/p&gt;

</description>
      <category>node</category>
      <category>backend</category>
      <category>web</category>
    </item>
    <item>
      <title>Laravel Jobs : Step By Step Implementation</title>
      <dc:creator>Sarthak Mahulikar</dc:creator>
      <pubDate>Wed, 27 Mar 2024 09:14:04 +0000</pubDate>
      <link>https://dev.to/sarthak619/laravel-jobs-step-by-step-implementation-39on</link>
      <guid>https://dev.to/sarthak619/laravel-jobs-step-by-step-implementation-39on</guid>
      <description>&lt;h2&gt;
  
  
  What is Laravel Jobs?
&lt;/h2&gt;

&lt;p&gt;Job refers to tasks that are executed asynchronously. Laravel provides a powerful queue system for managing and executing these jobs. Job can be any PHP code that needs to be executed outside of the typical request-response cycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why are Laravel jobs necessary?
&lt;/h2&gt;

&lt;p&gt;In a synchronous system, users have to wait until the task is completed. It will lead to long waiting time, sometimes it happens when the tasks are resource intensive. In such situations laravel jobs come into play.&lt;br&gt;
Laravel jobs provides you the functionality to handle the tasks in background, so it helps you for returning the web requests quickly.&lt;/p&gt;
&lt;h2&gt;
  
  
  When to use Laravel jobs?
&lt;/h2&gt;

&lt;p&gt;The scenarios where laravel jobs are effective are as below:&lt;br&gt;
&lt;strong&gt;1.Email Sending:&lt;/strong&gt; In sending emails to the user jobs help you handle the requests. This ensures that the user don't need to wait for long time for getting response. When you handle request using laravel job you can send the response to the user while at the same time the job task is working in the background.     &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.Data Processing:&lt;/strong&gt; Sometimes while storing the different forms of data such as image, documents. You need upload those data to a particular platform but storing it without job makes it more time consuming. Hence laravel jobs helps you to run and handle these processes in background and helps to minimize request-response cycle time.     &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3.Notifications:&lt;/strong&gt; If you have a system that sends notifications to the user you can use job for sending those notifications. You can schedule the notification job, laravel also provide the scheduling facility for the job such as daily, weekly ,etc. notifications.&lt;/p&gt;
&lt;h2&gt;
  
  
  Implementation Steps for Using Laravel Jobs
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Step-I:&lt;/strong&gt;&lt;br&gt;
For getting started with larevel jobs you will need a database table that holds the jobs. To generate migration related to that creates the table for job, run &lt;strong&gt;queue:table&lt;/strong&gt; Artisan Command and after migration is created. Use migrate command.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan queue:table

php artisan migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, you need to update the database driver by updating the value of &lt;strong&gt;QUEUE_CONNECTION&lt;/strong&gt; variable mentioned in &lt;strong&gt;.env&lt;/strong&gt; file of your application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;QUEUE_CONNECTION=database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step-II:&lt;/strong&gt;&lt;br&gt;
For creating jobs we have &lt;strong&gt;make:job&lt;/strong&gt; Artisan command. All the jobs you have created by default stored in the app/jobs directory.&lt;br&gt;
If the app/jobs directory doesn't exist in your application, you need not have to worry it will be created when you run the &lt;strong&gt;make:job&lt;/strong&gt; Artisan commmand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:job &amp;lt;job_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code you want to execute after running job should be written in the &lt;strong&gt;handle()&lt;/strong&gt; method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public function handle(): void
{
    // Write code here which you want to execute after running job
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Running the jobs we have &lt;strong&gt;queue:work&lt;/strong&gt; Artisan command.This command will start the queue worker and process the new jobs as they are pushed onto the queue. Once the &lt;strong&gt;queue:work&lt;/strong&gt; command started, it will run continuously until you stop it manually or you close the terminal window.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan queue:work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Example: Filtering Posts For Inappropriate Words
&lt;/h2&gt;

&lt;p&gt;In this example we will provide functionality to user that he can add post only which doesn't have any bad words If it has bad words then we will delete the post using the jobs.&lt;br&gt;
The code for the above is as below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ProcessTask implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     */
   private $postId;

    public function __construct($post_id)
    {
        $this-&amp;gt;postId=$post_id;
    }

    /**
     * Execute the job.
     */
    public function handle(): void
    {
        $post=Post::find($this-&amp;gt;postId);
        $badWords=["Donkey","Bloody","Damn","Dumb"];
        $badWordsFoundList=[];
        foreach($badWords as $badWord )
        {

                if(Str::contains($post-&amp;gt;description,$badWord))
                {

                    array_push($badWordsFoundList,$badWord);
                }

        }
       if(count($badWordsFoundList)!=0)
        {   $badWordsString='';

            foreach($badWordsFoundList as $badWordFound){
                $badWordsString.=" ".$badWordFound."  ";
            }

            echo "Deleting the post \n\n";
            $post-&amp;gt;delete();

           echo 'bad words found  the words are: '.$badWordsString;
        }      
        else{

            echo " Bad Word not found in the Post ";
        } 
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion:
&lt;/h2&gt;

&lt;p&gt;Laravel job provide a efficient solution for executing asynchronous tasks in your application and thus saves your time and improves efficiency of application. These are the steps that are required for creating a job in Laravel &lt;/p&gt;

</description>
      <category>php</category>
      <category>laravel</category>
      <category>backend</category>
      <category>web</category>
    </item>
  </channel>
</rss>
