<?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: sushmeet sunger</title>
    <description>The latest articles on DEV Community by sushmeet sunger (@sushmeet).</description>
    <link>https://dev.to/sushmeet</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%2F547554%2Fc9c35a08-da2a-487e-bf29-301a360773ac.jpeg</url>
      <title>DEV Community: sushmeet sunger</title>
      <link>https://dev.to/sushmeet</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sushmeet"/>
    <language>en</language>
    <item>
      <title>Leet Code Palindrome problem in Javascript</title>
      <dc:creator>sushmeet sunger</dc:creator>
      <pubDate>Wed, 12 Feb 2025 19:50:17 +0000</pubDate>
      <link>https://dev.to/sushmeet/leet-code-palindrome-problem-in-javascript-238n</link>
      <guid>https://dev.to/sushmeet/leet-code-palindrome-problem-in-javascript-238n</guid>
      <description>&lt;h2&gt;
  
  
  General Idea
&lt;/h2&gt;

&lt;p&gt;Given an integer, return whether true or false if it is a palindrome.&lt;/p&gt;

&lt;p&gt;** Approach 1&lt;br&gt;
So the easiest way to approach this is to convert the number into a string, break into an array, reverse the array, then join back the string and compare the original string and reversed string. Lets try this first and look at the &lt;em&gt;Time&lt;/em&gt; and &lt;em&gt;Space&lt;/em&gt; Complexity.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export function isPalindrome(x: number): boolean {
  // Convert number to string
  const numStr = x.toString(); // O(1)

  // Get reversed string
  const reversedString = numStr.split("").reverse().join("");

  // Compare original and reversed strings
  return numStr === reversedString;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Approach 1 Complexity
&lt;/h3&gt;

&lt;p&gt;Time Complexity is O(n)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;So when we convert the input integer to a string, it depends on the size of integer so O(n)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then we break the string into an array, so again O(n)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then we reverse array O(n)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Join the reversed array above into a string O(n)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Compare the 2 strings O(n)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So O(n) + O(n) + O(n) + O(n) + O(n) = O(n). &lt;/p&gt;

&lt;p&gt;Even though there are 5 different O(n) operations, we simplify it to just O(n) because:&lt;/p&gt;

&lt;p&gt;Constants don't matter in Big O notation - whether an algorithm takes n steps or 5n steps, the growth rate is still linear with respect to the input size.&lt;/p&gt;

&lt;p&gt;We care about the algorithmic scaling behavior as n gets very large, and at that point, the difference between n and 5n becomes negligible&lt;/p&gt;

&lt;p&gt;Space Complexity is O(n)&lt;br&gt;
We create additional strings and arrays:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;We create a new string &lt;code&gt;numStr&lt;/code&gt; from the original integer O(n)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;we create a new array from split O(n)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We have a reversed str O(n)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The solution is simple but not the most efficient for space complexity.&lt;/p&gt;

&lt;p&gt;** Approach 2 More Efficient and what we want.&lt;/p&gt;

&lt;p&gt;Let's look at a more optimized solution that avoids string conversion and uses a mathematical approach.&lt;/p&gt;

&lt;h3&gt;
  
  
  Approach 2 Complexity
&lt;/h3&gt;

&lt;p&gt;Time Complexity: O(log n)&lt;/p&gt;

&lt;p&gt;We only process half the digits&lt;br&gt;
For a number n, the number of digits is log₁₀(n)&lt;br&gt;
Each iteration processes one digit&lt;/p&gt;

&lt;p&gt;Space Complexity: O(1)&lt;/p&gt;

&lt;p&gt;We only use two variables regardless of input size:&lt;/p&gt;

&lt;p&gt;x (which we modify)&lt;br&gt;
reversedHalf&lt;/p&gt;

&lt;p&gt;Key optimizations:&lt;/p&gt;

&lt;p&gt;Early returns for negative numbers and single digits&lt;br&gt;
Only reverses half the number instead of the entire number&lt;br&gt;
No string conversion needed&lt;br&gt;
Handles both even and odd length numbers&lt;br&gt;
Uses constant extra space&lt;/p&gt;

&lt;p&gt;Example of how it works for number 1221:&lt;/p&gt;

&lt;p&gt;Initially: x = 1221, reversedHalf = 0&lt;br&gt;
First iteration: x = 122, reversedHalf = 1&lt;br&gt;
Second iteration: x = 12, reversedHalf = 12&lt;br&gt;
Loop ends as x ≤ reversedHalf&lt;br&gt;
Check if x === reversedHalf (12 === 12) → true&lt;/p&gt;

</description>
      <category>leetcode</category>
      <category>palindrome</category>
      <category>programming</category>
      <category>algorithms</category>
    </item>
    <item>
      <title>Leet Code Two Sum problem in Javascript</title>
      <dc:creator>sushmeet sunger</dc:creator>
      <pubDate>Sun, 08 Dec 2024 22:07:13 +0000</pubDate>
      <link>https://dev.to/sushmeet/two-sum-problem-in-javascript-4aj2</link>
      <guid>https://dev.to/sushmeet/two-sum-problem-in-javascript-4aj2</guid>
      <description>&lt;h2&gt;
  
  
  General Idea
&lt;/h2&gt;

&lt;p&gt;The &lt;strong&gt;Two Sum&lt;/strong&gt; problem is a classic algorithmic problem. It asks you to find two numbers in an array that add up to a specific *&lt;em&gt;target *&lt;/em&gt; that is provided and then return their indices from the given array.&lt;/p&gt;

&lt;h2&gt;
  
  
  Problem Statement
&lt;/h2&gt;

&lt;p&gt;Given an array of integers nums and an integer target, return the indices of the two numbers such that they add up to the target. Each input will have exactly one solution, and you may not use the same element twice.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Input: nums = [2, 7, 11, 15], target = 9&lt;br&gt;
Output: [0, 1]&lt;br&gt;
Explanation: nums[0] + nums[1] = 2 + 7 = 9&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Approach 1 Brute force
&lt;/h2&gt;

&lt;p&gt;First approach to any problem could just be to get something done and the easiest thing conceptually.&lt;/p&gt;

&lt;p&gt;Iterate through the array with two loops and check all pairs of numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const twoSum = (nums, target) =&amp;gt; {
  for(let i = 0; i &amp;lt; nums.length; i++) {
    for (let j = i + 1; j &amp;lt; nums.length; j++) {
      console.log(` i is ${nums[i]} and k is ${nums[j]}`)
      // lets check if we add the 2 numbers if it equals target
      if (target === nums[i] + nums[j]) {
        return [i, j]
      }
    }
  }
};

const nums = [2, 7, 11, 15];
const target = 9;
console.log(twoSum(nums, target));

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Approach 1 Complexity
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Time Complexity&lt;/strong&gt; is &lt;em&gt;O(n²)&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Nested loops checking every pair of numbers&lt;/li&gt;
&lt;li&gt;Checks every possible combination&lt;/li&gt;
&lt;li&gt;Becomes very slow with large arrays&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Space Complexity&lt;/strong&gt; is &lt;em&gt;O(1)&lt;/em&gt;&lt;br&gt;
1.We have created no new data structure&lt;/p&gt;
&lt;h2&gt;
  
  
  Approach 2 More Efficient and what we want.
&lt;/h2&gt;

&lt;p&gt;We will use a hash map to solve this. Let's explain this algorithm a bit&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;We use a hash map (object in JavaScript) to store numbers we've seen&lt;/li&gt;
&lt;li&gt;For each number, we calculate its complement (target - current number)&lt;/li&gt;
&lt;li&gt;We check if the complement exists in our map&lt;/li&gt;
&lt;li&gt;If it does, we've found our two numbers and return their indices&lt;/li&gt;
&lt;li&gt;If not, we add the current number to the map&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So first solution could be using the regular JS object and building our HashMap that way&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const twoSumOptimizedRegularObject = (nums, target) =&amp;gt; {
  const objectStuff = {}

  // write a for loop, to go through the arr
  for (let i = 0; i &amp;lt; nums.length; i++) {
    const complement = target - nums[i] 

    if (complement in objectStuff) {
      return [objectStuff[complement],i]
    }
    objectStuff[nums[i]] = i 
  }
}

const nums = [2, 7, 11, 15];
const target = 9;
console.log(twoSumOptimizedRegularObject(nums, target));

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second solution is actually using the Map Data Structure in JS.This allows for a more stricter and more robust implementations, using a Map object (introduced in ES6) and is often preferred. A Map provides explicit hash map behavior and avoids some quirks of JavaScript objects, like inheriting properties from Object.prototype.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const twoSumOptimized = (nums, target) =&amp;gt; {
  const mapOfStuff = new Map()

  // write a for loop, to go through the arr
  for (let i = 0; i &amp;lt; nums.length; i++) {
    let complement = target - nums[i]

    if (mapOfStuff.has(complement)) {
      return [mapOfStuff.get(complement), i]
    }
    mapOfStuff.set(nums[i], i)
  }

}

const nums = [2, 7, 11, 15];
const target = 9;
console.log(twoSumOptimized(nums, target));

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Approach 2 Complexity
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Time Complexity&lt;/strong&gt; is &lt;em&gt;O(n)&lt;/em&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Single pass through the array&lt;/li&gt;
&lt;li&gt;Hash map provides O(1) lookup&lt;/li&gt;
&lt;li&gt;Total time scales linearly with array size&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Space Complexity&lt;/strong&gt; is O(n)&lt;br&gt;
In worst case, we might store nearly all numbers&lt;br&gt;
Trade-off between time and memory efficiency&lt;/p&gt;

&lt;h2&gt;
  
  
  Caveats
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Empty array&lt;/li&gt;
&lt;li&gt;No solution exists&lt;/li&gt;
&lt;li&gt;Multiple solution are possible. In this case, ask if you return after the first iteration.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>leetcode</category>
    </item>
    <item>
      <title>How to Install React in 5 minutes</title>
      <dc:creator>sushmeet sunger</dc:creator>
      <pubDate>Tue, 03 Jan 2023 01:53:24 +0000</pubDate>
      <link>https://dev.to/sushmeet/how-to-install-react-in-5-minutes-dmo</link>
      <guid>https://dev.to/sushmeet/how-to-install-react-in-5-minutes-dmo</guid>
      <description>&lt;p&gt;Heard a lot about React!! Looking to give it a try on your computer but unsure as to how you can set up your development environment. No worries we got you covered.&lt;/p&gt;

&lt;p&gt;Firstly let's ensure you have NodeJS installed on your machine.&lt;br&gt;
We will install nvm (node version manager) which will in turn let us install multiple versions of NodeJS, so we can choose whichever one we need to run.&lt;/p&gt;

&lt;p&gt;Type the below command to get the latest&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;nvm install node
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't have nvm than you can first try installing nvm.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We will install a React Application and have it configured with Visual Studio Code (VS Code) which will allow you to edit, and create new react apps.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install VS code by going to the side VS Code Site &lt;a href="https://code.visualstudio.com/"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Once installed, open VS code, and open an Integrated Terminal within VS Code. You can do this by &lt;code&gt;Use the View &amp;gt; Terminal or Terminal &amp;gt; New Terminal menu commands.
&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Now go to this Integrated Terminal and ensure that you are in the space where you want to create your project. So if you want to create your project in documents just type.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd Documents 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Once you are in the location, that you want to create your code folder, type the following command below. So in the command below where I have &lt;code&gt;nameOfYourAppHere&lt;/code&gt; you can put any name for your app, so whatever you like.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app nameOfYourAppHere
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Once this is done you should have React and all of it's package dependencies installed&lt;/li&gt;
&lt;li&gt;Now let's start you React Application by typing
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd nameOfYourAppHere
npm start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;In your browser go to &lt;code&gt;http://localhost:3000&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You will see the react logo spinning and that is your application.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>API routes with Vercel Serverless Functions and NextJS</title>
      <dc:creator>sushmeet sunger</dc:creator>
      <pubDate>Fri, 23 Sep 2022 05:07:40 +0000</pubDate>
      <link>https://dev.to/sushmeet/api-routes-with-vercel-serverless-functions-and-nextjs-5goa</link>
      <guid>https://dev.to/sushmeet/api-routes-with-vercel-serverless-functions-and-nextjs-5goa</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--0VXzo2-s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhttrymc8zfucgntdly7.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--0VXzo2-s--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mhttrymc8zfucgntdly7.jpg" alt="Image description" width="880" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You use Next.js for your frontend Applications. Did you also know that you could use Next.js to create a Node API and essentially have a back end application 😃!!!. &lt;/p&gt;

&lt;p&gt;That's right no need to set up a separate back end application using Nodejs or other webframeworks like Express JS or Fastify.&lt;/p&gt;

&lt;p&gt;So I did know about this by reading the docs, but something that stumbled me a bit was there were apparently two choices that are presented to us.&lt;/p&gt;

&lt;p&gt;First being Vercel's Serverless Functions and second being  Next.js API routes. Both allow you to serve API endpoints 🤔. &lt;/p&gt;

&lt;p&gt;Vercel is the company behind Next.js , and for me initially the line was blurry because both implementations seemed very similar(spoiler 🚨 this is not true). So in this article we will go over the differences between the two approaches, which approach might be right for you and how to move forward with those approaches. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Option1: Serverless functions with Vercel&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I2-ZqhWH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5r33qlzul2o02s7extve.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I2-ZqhWH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5r33qlzul2o02s7extve.jpg" alt="Image description" width="880" height="387"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Creating Serverless functions with Vercel has only one package dependency and that is Vercel and you don't need Next.js. This a zero configuration deployment. &lt;/p&gt;

&lt;p&gt;To deploy Serverless Functions, you can put files with&lt;br&gt;
extensions matching &lt;a href="https://vercel.com/docs/concepts/functions/supported-languages"&gt;supported languages&lt;/a&gt; and exported functions in the &lt;code&gt;/api&lt;/code&gt; directory at the root of your project.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Serverless functions  with Vercel would be great if you are looking to create Microservices and have multiple applications consume your API.&lt;/li&gt;
&lt;li&gt;Supported Languages with Vercel include &lt;em&gt;Node.js&lt;/em&gt;, &lt;em&gt;Go&lt;/em&gt;, &lt;em&gt;Python&lt;/em&gt; and &lt;em&gt;Ruby&lt;/em&gt;. More info and examples on this from official docs &lt;a href="https://vercel.com/docs/concepts/functions/supported-languages"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How to install/use Vercel Serverless Functions&lt;/strong&gt;&lt;br&gt;
So if you feel Option 1 is the choice you are looking for here are some resources to get Started&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A great step by step detailed blog post &lt;a href="https://www.frontend-devops.com/blog/build-deploy-a-vercel-api"&gt;here&lt;/a&gt; written by &lt;a href="https://twitter.com/TheHouseAVAX"&gt;TheHouseAVAX&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A great &lt;a href="https://www.youtube.com/watch?v=BhArBPtW6Ms"&gt;Video Tutorial&lt;/a&gt; by &lt;a href="https://twitter.com/james_r_perkins"&gt;James Perkins&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Vercel's official documentation on Serveless functions &lt;a href="https://vercel.com/docs/concepts/functions/serverless-functions"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Option2: Creating API routes with Next.js&lt;/strong&gt;&lt;br&gt;
 Next.js API routes also give us the ability to create &lt;br&gt;
 serverless API routes and are pre configured to be the perfect backend companion to a Next.js app. Next.js is needed as a dependency for this.&lt;/p&gt;

&lt;p&gt;Creating API routes with Next.js can be done by creating a folder called  &lt;code&gt;/api/&lt;/code&gt; in the &lt;code&gt;pages&lt;/code&gt; Directory (not root directory like for Option 1) and adding files to it. Any file inside the folder &lt;code&gt;pages/api&lt;/code&gt; will be treated as an API endpoint.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;These bundles are server side only and won't increase your client-side bundle size. So the API folder will never be shipped to your browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Caveats&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They by default are &lt;em&gt;same-origin only&lt;/em&gt;, meaning if your domain is &lt;a href="https://mySite.com/"&gt;https://mySite.com/&lt;/a&gt;, then requests from that domain &lt;strong&gt;ONLY&lt;/strong&gt; can access your API. If you would like other apps (from other domains) to access this API it would be denied. You can customize such behaviour by wrapping the request handler with the CORS middleware meaning, we can allow some other trusted sites apart from &lt;a href="http://myDifferentSite.com/"&gt;http://myDifferentSite.com/&lt;/a&gt;  to access the API&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;How to use Next.js API Routes&lt;/strong&gt;&lt;br&gt;
Some resources for Option 2&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The Next.js documentation is truly the gold standard &lt;a href="https://nextjs.org/docs/api-routes/introduction"&gt;here&lt;/a&gt;. It's concise, easy to digest and covers all options for you.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A free video tutorial on Egghead.io &lt;a href="https://egghead.io/lessons/react-build-straightforward-api-with-next-js-api-routes"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Similarities&lt;/strong&gt; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The way the code is written for both these options is very similar so it's nice to have that consistency from both these options.&lt;/li&gt;
&lt;li&gt;So you could choose either option and not have to relearn too much. &lt;/li&gt;
&lt;/ul&gt;

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

&lt;ul&gt;
&lt;li&gt;Under the hood both options (1 and 2) are the same: It's an abstraction over Lambda and other serverless functions that is meant to be a zero configuration service.&lt;/li&gt;
&lt;li&gt;If the API you are building is exclusively for your Next.js Front-End companion App then Next.js API routes are the way to go. It is the perfect backend companion that by default restricts origin and is usable with middleware.&lt;/li&gt;
&lt;li&gt;You could technically achieve the same result with both options but their configurations cater to different audiences / usecases.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nextjs</category>
      <category>javascript</category>
      <category>react</category>
      <category>serverless</category>
    </item>
    <item>
      <title>Mobile Development with React Native</title>
      <dc:creator>sushmeet sunger</dc:creator>
      <pubDate>Fri, 23 Sep 2022 04:48:38 +0000</pubDate>
      <link>https://dev.to/sushmeet/how-to-begin-mobile-dev-with-react-native-204f</link>
      <guid>https://dev.to/sushmeet/how-to-begin-mobile-dev-with-react-native-204f</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&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%2Fjgzh16erfo6gjx7hp6v6.jpg" 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%2Fjgzh16erfo6gjx7hp6v6.jpg" alt="Image description" width="500" height="439"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This react native tutorial should help you to get a high level understanding of how to begin or get started with Mobile Development with React Native. &lt;/p&gt;

&lt;p&gt;There are two ways to get your React Native applications bootstrapped. The first way is to use &lt;a href="https://expo.dev/" rel="noopener noreferrer"&gt;Expo&lt;/a&gt; Managed App (we will get into what a managed app is later) and this is the easiest and most hassle free way to get started. The second way is to use React Native CLI and create a Bare App. This process is definitely more involved but gives a lot more control and access to libraries which might not be available via Expo. &lt;/p&gt;

&lt;h2&gt;
  
  
  Managed vs Bare Applications
&lt;/h2&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%2Fq91tbwigpd51itgjcwno.jpg" 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%2Fq91tbwigpd51itgjcwno.jpg" alt="Image description" width="500" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Pros for Managed Apps
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Managed Applications is the way to go if you would like expo to take care of everything for you. You only write Javascript or Typescript and expo helps with everything else from publishing your project, providing links to share with other people, and even releasing the Apps (IOS and Android) on the App store. Official Documentation describing the difference between them is &lt;a href="https://docs.expo.dev/introduction/managed-vs-bare/" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Expo removes a lot of the tedious set up portions for you and provides you with a plethora of API's and Services that can be used to make your development process smoother. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;You can easily share the Apps with anyone using &lt;a href="https://docs.expo.dev/get-started/installation/#2-expo-go-app-for-ios-and" rel="noopener noreferrer"&gt;Expo Go&lt;/a&gt; to get feedback during the development process. Once you publish your app with Expo, you will get a URL, which can be shared with anyone who has the Expo Go app installed and they can then view and run your application on their native devices. This is also possible for Bare Apps with Expo, albeit it requires a bit more work.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Cons for Managed Apps
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Downsides to Managed Apps is some features and libraries are only available as React Native Modules and hence will not work with a Managed App from Expo. If you find yourself in this position there is a feature to eject from Expo.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Managed Apps are usually larger in size because of all the prepackaged libs that are associated with them so they do increase the size of your vanilla application. This could be a deterrent for some people with limited space on their devices.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Bare Applications (Expo)
&lt;/h3&gt;

&lt;p&gt;Expo does give you the option of having bare apps and thus you get some support from expo, while also getting the freedom of using any libraries that use react native modules. Expo is usually a version behind on React native , but the benefits of that is they have a lot of testing before they upgrade to the latest offering from React Native.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bare Apps with React Native CLI
&lt;/h3&gt;

&lt;p&gt;This gets as close to bare metal as you can. You get to choose the libs you want so you application size will definitely be the smallest possible. You also get access to the latest features versions of React Native.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&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%2Fcoai9j5rk24psqafy5sp.jpg" 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%2Fcoai9j5rk24psqafy5sp.jpg" alt="Image description" width="500" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The official Documentation to install expo is available &lt;a href="https://reactnative.dev/docs/environment-setup" rel="noopener noreferrer"&gt;here&lt;/a&gt; and is extremely precise and detailed. &lt;br&gt;
Install the expo cli&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;npm install -g expo-cli&lt;/code&gt; 
BootStrap a new project called AwesomeProject&lt;/li&gt;
&lt;li&gt;&lt;code&gt;expo init AwesomeProject&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Install Options
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Now using Expo CLI we will init a new expo project. You will have two options creating a &lt;em&gt;bare&lt;/em&gt; project or a &lt;em&gt;managed&lt;/em&gt; project. &lt;/li&gt;
&lt;li&gt;Choose the Managed Options and proceed.&lt;/li&gt;
&lt;li&gt; &lt;code&gt;yarn start&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Choose your platform IOS, Android or Web.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common Installation Problems (with expo installation)
&lt;/h2&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%2Ff7r8v0lcp65jk05rkozk.jpg" 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%2Ff7r8v0lcp65jk05rkozk.jpg" alt="Image description" width="500" height="334"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Ensure that you have the latest version of Xcode Running for IOS, and Android Studio if you are developing for Android.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When you &lt;code&gt;yarn start&lt;/code&gt; and your App doesn't open up in the simulator and you get an error, then the first thing to try is open the simulator with Native IDE. So use Xcode and Open simulator or Android Studio and open simulator. Once that works then you can close Xcode / Android Studio. Now try starting you App again &lt;code&gt;yarn start&lt;/code&gt; and choose IOS or Android, it should open up your simulator and you should see your App running&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&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%2F66gu98g55e1k3ije84gw.jpg" 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%2F66gu98g55e1k3ije84gw.jpg" alt="Image description" width="500" height="334"&gt;&lt;/a&gt;&lt;br&gt;
If you are new to React Native Mobile Development and are just looking to hit the ground running, then Expo Managed Apps is a great way to do that. They also provide a lot of services that enable you to release your code for both Apple and Google PlayStores. &lt;/p&gt;

&lt;p&gt;However if you would like to use specific react native modules that don't have expo equivalents, and care about your application size, and just want more granular control, then you have Choice of having Bare Apps with expo or Just with React Native CLI. &lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>react</category>
      <category>mobile</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Props Drilling and understanding React Context via them</title>
      <dc:creator>sushmeet sunger</dc:creator>
      <pubDate>Sat, 08 Jan 2022 05:26:50 +0000</pubDate>
      <link>https://dev.to/sushmeet/props-drilling-and-understand-react-context-2f8p</link>
      <guid>https://dev.to/sushmeet/props-drilling-and-understand-react-context-2f8p</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;If you pass props around to multiple components, where in some cases, the elements receiving them are not even using them, then you are prop drilling. It's like if you have 3 components A, B and C and you pass prop &lt;code&gt;name&lt;/code&gt; from component &lt;code&gt;&amp;lt;A name="Tony" /&amp;gt;&lt;/code&gt; to component &lt;code&gt;&amp;lt;B /&amp;gt;&lt;/code&gt;. But component B doesn't even use the &lt;code&gt;name&lt;/code&gt;  prop. It simply passes it on to component &lt;code&gt;C&lt;/code&gt; where the prop is actually used.&lt;/p&gt;

&lt;p&gt;Context API provided a mechanism to pass data through the component tree, without having the need to pass props manually down every level.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's begin with an example
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";

const App = () =&amp;gt; {
  const [input, setInput] = useState("");
  const inputHandler = (e) =&amp;gt; setInput(e.target.value);

  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello CodeSandbox&amp;lt;/h1&amp;gt;
      &amp;lt;label&amp;gt;Input &amp;lt;/label&amp;gt;
      &amp;lt;input value={input} onChange={inputHandler} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};
&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%2Fyv775lfukknmvuqlt0rc.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%2Fyv775lfukknmvuqlt0rc.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here we have a simple input box, where you can enter some text.&lt;/p&gt;

&lt;p&gt;Let's refactor this component so that the state and the onChange handler are passed from the App component to another component called InputStuff.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";

const InputStuff = ({ input, inputHandler }) =&amp;gt; {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello CodeSandbox&amp;lt;/h1&amp;gt;
      &amp;lt;label&amp;gt;Input &amp;lt;/label&amp;gt;
      &amp;lt;input value={input} onChange={inputHandler} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

const App = () =&amp;gt; {
  const [input, setInput] = useState("");
  const inputHandler = (e) =&amp;gt; setInput(e.target.value);

  return &amp;lt;InputStuff input={input} inputHandler={inputHandler} /&amp;gt;;
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The InputStuff needs a reference to the &lt;code&gt;input&lt;/code&gt; and &lt;code&gt;inputHandler&lt;/code&gt; state, so we're sending some props there. Let's refactor it once more to add another layer in our component tree.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { useState } from "react";

const InputLabel = () =&amp;gt; {
  return &amp;lt;label&amp;gt;Input &amp;lt;/label&amp;gt;;
};

const InputDisplay = ({ input, inputHandler }) =&amp;gt; {
  return &amp;lt;input value={input} onChange={inputHandler} /&amp;gt;;
};

const InputStuff = ({ input, inputHandler }) =&amp;gt; {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello CodeSandbox&amp;lt;/h1&amp;gt;
      &amp;lt;InputLabel /&amp;gt;
      &amp;lt;InputDisplay input={input} inputHandler={inputHandler} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

const App = () =&amp;gt; {
  const [input, setInput] = useState("");
  const inputHandler = (e) =&amp;gt; setInput(e.target.value);

  return &amp;lt;InputStuff input={input} inputHandler={inputHandler} /&amp;gt;;
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;CodeSandbox URL showing the above code &lt;a href="https://codesandbox.io/s/props-drilling-example-before-h9hwj?file=/src/App.js" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Voila this is prop drilling. To get the &lt;code&gt;input&lt;/code&gt; state and &lt;code&gt;inputHandler&lt;/code&gt; handler to the right places, we have to drill props through the InputStuff component. The InputStuff component itself doesn't actually need those props to function, but we have to still accept them and forward those props because its children need them.&lt;/p&gt;

&lt;p&gt;Props drilling has both pros and cons. In a contrived example like this we do not have much issues, but once you have deeper layers and need some props everywhere, we can take advantage of the React Context API.&lt;/p&gt;

&lt;p&gt;Here is the above example using React Context API&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState, useContext, createContext } from "react";

const InputContext = createContext();

const InputLabel = () =&amp;gt; {
  return &amp;lt;label&amp;gt;Input &amp;lt;/label&amp;gt;;
};

const InputDisplay = () =&amp;gt; {
  const { input, inputHandler } = useContext(InputContext);
  return &amp;lt;input value={input} onChange={inputHandler} /&amp;gt;;
};

const InputStuff = ({ input, inputHandler }) =&amp;gt; {
  return (
    &amp;lt;div className="App"&amp;gt;
      &amp;lt;h1&amp;gt;Hello CodeSandbox&amp;lt;/h1&amp;gt;
      &amp;lt;InputLabel /&amp;gt;
      &amp;lt;InputDisplay input={input} inputHandler={inputHandler} /&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

const App = () =&amp;gt; {
  const [input, setInput] = useState("");
  const inputHandler = (e) =&amp;gt; setInput(e.target.value);

  return (
    &amp;lt;InputContext.Provider value={{ input, inputHandler }}&amp;gt;
      &amp;lt;InputStuff input={input} inputHandler={inputHandler} /&amp;gt;
    &amp;lt;/InputContext.Provider&amp;gt;
  );
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the codesandbox ex using Context API &lt;a href="https://codesandbox.io/s/prop-drills-with-react-context-21jsr?file=/src/App.js:23-861" rel="noopener noreferrer"&gt;here&lt;/a&gt;&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;We understood props drilling and what the Context API are.&lt;/li&gt;
&lt;li&gt;Props Drilling by itself is fine and is useful to trace the path of how data flows, and hence eventually make refactoring and changes easy although this can spiral out of hand quite easily&lt;/li&gt;
&lt;li&gt;Context API can be used to share data that is considered global for React Components. It provides a mechanism to have props available at any level, without explicitly passing the props. It is ideally used for passing &lt;code&gt;Theme&lt;/code&gt;, &lt;code&gt;Locale&lt;/code&gt; to many components in an application.&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Add Typescript to an existing NextJS Project in 5 mins</title>
      <dc:creator>sushmeet sunger</dc:creator>
      <pubDate>Tue, 28 Dec 2021 02:54:44 +0000</pubDate>
      <link>https://dev.to/sushmeet/add-typescript-to-an-existing-nextjs-project-in-5-mins-2mik</link>
      <guid>https://dev.to/sushmeet/add-typescript-to-an-existing-nextjs-project-in-5-mins-2mik</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&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%2Fn135oaeqxz862cdyhjs0.jpg" 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%2Fn135oaeqxz862cdyhjs0.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So your team and you have heard all the hype about Typescript and would like to add it to your existing NextJS project. Or you are  a seasoned Typescript expert and want to introduce it at your current organization, so as to give everyone a chance to opt in and use Typescript and Javascript side by side. &lt;em&gt;So how complicated is this and where do you start?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Process&lt;/strong&gt;&lt;br&gt;
Usually adding typescript to any project requires you to have a &lt;code&gt;tsconfig.json&lt;/code&gt;, which sits at the root of a project.The &lt;code&gt;tsconfig.json&lt;/code&gt; file specifies the root files and the compiler options required to compile the project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lets Do This&lt;/strong&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%2Fml4k7e49mcyldyfz00ot.jpg" 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%2Fml4k7e49mcyldyfz00ot.jpg" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create an empty file named tsconfig.json at the root of your project. You can do so by creating a new file in your editor or typing the following command &lt;/li&gt;
&lt;/ul&gt;

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

touch tsconfig.json


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Now just run your Next application as usual with &lt;code&gt;npm run dev&lt;/code&gt; or &lt;code&gt;yarn dev&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Once you do this, NextJS will try to help you for the rest of the installation process, which requires installing typescript and it's dependencies. Have a look at your terminal or server and copy and paste the command that is present. &lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  With NPM
&lt;/h1&gt;

&lt;p&gt;npm install --save-dev typescript @types/react @types/node&lt;/p&gt;

&lt;h1&gt;
  
  
  With Yarn
&lt;/h1&gt;

&lt;p&gt;yarn add --dev typescript @types/react @types/node&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
This is what the auto-generated tsconfig.json should look like

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;{&lt;br&gt;
  "compilerOptions": {&lt;br&gt;
    "target": "es5",&lt;br&gt;
    "lib": ["dom", "dom.iterable", "esnext"],&lt;br&gt;
    "allowJs": true,&lt;br&gt;
    "skipLibCheck": true,&lt;br&gt;
    "strict": true,&lt;br&gt;
    "forceConsistentCasingInFileNames": true,&lt;br&gt;
    "noEmit": true,&lt;br&gt;
    "esModuleInterop": true,&lt;br&gt;
    "module": "esnext",&lt;br&gt;
    "moduleResolution": "node",&lt;br&gt;
    "resolveJsonModule": true,&lt;br&gt;
    "isolatedModules": true,&lt;br&gt;
    "jsx": "preserve",&lt;br&gt;
    "incremental": true&lt;br&gt;
  },&lt;br&gt;
  "include": ["next-env.d.ts", "&lt;strong&gt;/*.ts", "&lt;/strong&gt;/*.tsx"],&lt;br&gt;
  "exclude": ["node_modules"]&lt;br&gt;
}&lt;/p&gt;



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



&amp;gt; _Important_
 These are dev dependencies and are needed only in your development workflow but not while running your code.

**Tadaaa**

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pxrob5akitqbpyi9ldad.jpg)

- Now restart your server and you will see `next-env.d.ts` file created at the root of your server. This file ensures Next.js types are picked up by the TypeScript compiler. You cannot remove it or edit it as it can change at any time.
-  You will also see the `.tsconfig.json` file to be pre-populated for you.
- Now that you have typescript installed, you can start converting your `.js` files into `.tsx`, or just start creating new `.tsx` files. 
- TypeScript strict mode is turned off by default. When you feel comfortable with TypeScript, it's recommended to turn it on in your tsconfig.json. like so ` "strict": true`

**References**

-  [Official NextJS documentation](https://nextjs.org/docs/basic-features/typescript)
- [Github Example](https://github.com/vercel/next.js/tree/canary/examples/with-typescript)




&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>typescript</category>
      <category>nextjs</category>
    </item>
  </channel>
</rss>
