<?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: yashrajsinh chauhan</title>
    <description>The latest articles on DEV Community by yashrajsinh chauhan (@y2j_0_0).</description>
    <link>https://dev.to/y2j_0_0</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%2F1284719%2Ffe3936cd-ebd6-4dd9-bd76-172030f57539.png</url>
      <title>DEV Community: yashrajsinh chauhan</title>
      <link>https://dev.to/y2j_0_0</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/y2j_0_0"/>
    <language>en</language>
    <item>
      <title>What is dependency injection in .Net core?</title>
      <dc:creator>yashrajsinh chauhan</dc:creator>
      <pubDate>Mon, 08 Apr 2024 13:08:46 +0000</pubDate>
      <link>https://dev.to/y2j_0_0/what-is-dependency-injection-in-net-core-471k</link>
      <guid>https://dev.to/y2j_0_0/what-is-dependency-injection-in-net-core-471k</guid>
      <description>&lt;p&gt;The concept of &lt;a href="https://en.wikipedia.org/wiki/Dependency_injection"&gt;Dependency Injection&lt;/a&gt;, a design pattern that aids in crafting applications with loose coupling, is utterly breathtaking. It’s like watching a master artist at work, ensuring that objects are equipped with only the essential dependencies needed to accomplish their tasks. This level of precision and efficiency is nothing short of awe-inspiring!&lt;/p&gt;

&lt;p&gt;The awe-inspiring world of Dependency Injection (DI) unfolds with three magnificent types — Construction Injection, Setter Injection, and Interface-based Injection. The Construction Injection type of DI is a marvel in itself as it accepts dependencies right at the constructor level. This means that when an object of the class is born, its dependency sails smoothly through the constructor of the class. It’s like witnessing a beautiful dance between objects, creating a strong dependency contract.&lt;/p&gt;

&lt;p&gt;Then we have Setter Injection, also known as property injection — another wonder in this realm! In this form of DI, dependencies are passed through public property instead of the constructor. It’s like having an open door policy where dependencies can come and go as needed! However, it doesn’t provide a strong dependency contract between objects.&lt;/p&gt;

&lt;p&gt;Finally comes Interface-based Dependency Injection — where common interfaces are created and other classes implement these interfaces to inject their dependencies. In this awe-inspiring type of DI, you can choose to use either Constructor or Setter injection methods! Isn’t it amazing how flexible and accommodating technology can be?&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>dotnet</category>
      <category>dotnetcore</category>
    </item>
    <item>
      <title>How to Connect MSSQL with Node.js</title>
      <dc:creator>yashrajsinh chauhan</dc:creator>
      <pubDate>Mon, 19 Feb 2024 10:52:40 +0000</pubDate>
      <link>https://dev.to/y2j_0_0/how-to-connect-mssql-with-nodejs-22pn</link>
      <guid>https://dev.to/y2j_0_0/how-to-connect-mssql-with-nodejs-22pn</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcw9xx4u07hpy4rur7kf2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcw9xx4u07hpy4rur7kf2.jpg" alt="This article is about How we can connect nodejs and mssql" width="750" height="422"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In this tutorial, we'll explore how to connect Microsoft SQL Server (MSSQL) with Node.js using the Express framework to create an API. We'll use NPM (Node Package Manager) to install the necessary packages.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Prerequisites: Ensure you have Node.js installed on your machine.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Setting Up the Project&lt;/li&gt;
&lt;li&gt;Create a new folder named dbConnection and open it in your code editor (e.g., VSCode).&lt;/li&gt;
&lt;li&gt;Initialize a new Node.js project by running &lt;code&gt;npm init&lt;/code&gt; in the terminal. Press Enter for default options or use &lt;code&gt;npm init -y&lt;/code&gt; for quick initialization.&lt;/li&gt;
&lt;li&gt;Install the required packages: &lt;code&gt;npm install express mssql&lt;/code&gt;. This will add express and mssql to your project's package.json file.&lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Creating the Server
Create a JavaScript file named server.js and write the following code:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;javascript&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const express = require("express");&lt;/code&gt;&lt;br&gt;
&lt;code&gt;const sql = require("mssql");&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;const app = express();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;// SQL Server configuration&lt;br&gt;
&lt;code&gt;var config = {&lt;br&gt;
    "user": "  ", // Database username&lt;br&gt;
    "password": "  ", // Database password&lt;br&gt;
    "server": "  ", // Server IP address&lt;br&gt;
    "database": "Training", // Database name&lt;br&gt;
    "options": {&lt;br&gt;
        "encrypt": false // Disable encryption&lt;br&gt;
    }&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;// Connect to SQL Server&lt;br&gt;
&lt;code&gt;sql.connect(config, err =&amp;gt; {&lt;br&gt;
    if (err) {&lt;br&gt;
        throw err;&lt;br&gt;
    }&lt;br&gt;
    console.log("Connection Successful!");&lt;br&gt;
});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;// Define route for fetching data from SQL Server&lt;br&gt;
&lt;code&gt;app.get("/", (request, response) =&amp;gt; {&lt;br&gt;
    // Execute a SELECT query&lt;br&gt;
    new sql.Request().query("SELECT * FROM Employee", (err, result) =&amp;gt; {&lt;br&gt;
        if (err) {&lt;br&gt;
            console.error("Error executing query:", err);&lt;br&gt;
        } else {&lt;br&gt;
            response.send(result.recordset); // Send query result as response&lt;br&gt;
            console.dir(result.recordset);&lt;br&gt;
        }&lt;br&gt;
    });&lt;br&gt;
});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;// Start the server on port 3000&lt;br&gt;
&lt;code&gt;app.listen(3000, () =&amp;gt; {&lt;br&gt;
    console.log("Listening on port 3000...");&lt;br&gt;
});&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feasidre5dnfa3z33axek.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feasidre5dnfa3z33axek.png" alt="Output of the code" width="800" height="428"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;&lt;br&gt;
We use the express and mssql packages to set up an Express server and establish a connection to MSSQL database, respectively.&lt;/p&gt;

&lt;p&gt;The config object contains the database connection details, including the username, password, server IP, and database name. The encrypt option is set to false to disable encryption for the connection.&lt;/p&gt;

&lt;p&gt;After establishing the connection, we define a route (/) to fetch data from the "Employee" table in the database. When this route is accessed, a SELECT query is executed to retrieve all records from the table. The query result is sent back as the response to the client.&lt;/p&gt;

&lt;p&gt;Finally, the server is started on port 3000, and a message indicating successful startup is logged to the console.&lt;/p&gt;

&lt;p&gt;With this setup, you can access the API endpoint (&lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt;) in your browser or send HTTP requests to fetch data from the MSSQL database.&lt;/p&gt;

&lt;p&gt;That's it! You've successfully connected MSSQL with Node.js using Express.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now you are ready to apply in GOOGLE. 😊&lt;/strong&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  NodeJS #MSSQL #Express #API #Database #Tutorial #Programming #Development #WebDevelopment #Backend #SQLServer #NodePackageManager #NPM #JavaScript #Code #SoftwareDevelopment #TechTutorial
&lt;/h1&gt;

</description>
      <category>node</category>
      <category>sqlserver</category>
      <category>sql</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
