<?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: Tushar Pandey</title>
    <description>The latest articles on DEV Community by Tushar Pandey (@tusharpandey13).</description>
    <link>https://dev.to/tusharpandey13</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%2F245088%2Fc8d84e59-2303-4768-9820-e5c8d1a9eb18.jpeg</url>
      <title>DEV Community: Tushar Pandey</title>
      <link>https://dev.to/tusharpandey13</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tusharpandey13"/>
    <language>en</language>
    <item>
      <title>Next + Tailwind = Awesome Portfolio</title>
      <dc:creator>Tushar Pandey</dc:creator>
      <pubDate>Sun, 25 Jul 2021 13:47:41 +0000</pubDate>
      <link>https://dev.to/tusharpandey13/next-tailwind-awesome-portfolio-2ngn</link>
      <guid>https://dev.to/tusharpandey13/next-tailwind-awesome-portfolio-2ngn</guid>
      <description>&lt;p&gt;Hi everyone. This post contains a link to my new &lt;a href="https://tusharpandey13.github.io/"&gt;portfolio website&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is made using NextJS and TailwindCSS. I did the mockup in figma. It is hosted on github pages, as a static site.&lt;/p&gt;

&lt;p&gt;Any constructive critism is welcome! I would love to read your comments about the site.&lt;/p&gt;

&lt;p&gt;Cheers ✌️&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>portfolio</category>
      <category>webdev</category>
      <category>tailwindcss</category>
    </item>
    <item>
      <title>Portfolio Review</title>
      <dc:creator>Tushar Pandey</dc:creator>
      <pubDate>Sun, 30 Aug 2020 11:53:05 +0000</pubDate>
      <link>https://dev.to/tusharpandey13/portfolio-review-3beg</link>
      <guid>https://dev.to/tusharpandey13/portfolio-review-3beg</guid>
      <description>&lt;p&gt;&lt;a href="https://tusharpandey13.github.io/"&gt;https://tusharpandey13.github.io/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I finally completed it! All within 2 days too!&lt;/p&gt;

&lt;p&gt;Please tell me about your suggestions and give creative criticism :)&lt;/p&gt;

</description>
      <category>react</category>
      <category>portfolio</category>
      <category>scss</category>
      <category>review</category>
    </item>
    <item>
      <title>Getting On with ES6 &amp; NodeJS &amp; eslint (without Babel !)</title>
      <dc:creator>Tushar Pandey</dc:creator>
      <pubDate>Mon, 24 Aug 2020 17:58:00 +0000</pubDate>
      <link>https://dev.to/tusharpandey13/getting-on-with-es6-nodejs-eslint-without-babel-4ip7</link>
      <guid>https://dev.to/tusharpandey13/getting-on-with-es6-nodejs-eslint-without-babel-4ip7</guid>
      <description>&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;So, I'm making a Node - Express - Mongo server boilerplate to get the hang of it and I found out that Node now has support for &lt;strong&gt;es6&lt;/strong&gt; modules by default! :)&lt;/p&gt;

&lt;p&gt;This post will go through the process of creating one such project with es6 support, eslint configuration and some hacks :P  &lt;/p&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Note:
&lt;/h3&gt;

&lt;p&gt;This tutorial involves setting the &lt;code&gt;--es-module-specifier-resolution=node\"&lt;/code&gt; flag in the command line of node, which is an experimental flag.   This is the 'hack' mentioned above. This is done in order to omit the '.js' file extension while importing modules. However, if you are uncomfortable with experimental tags, you could either use '.js' extensions everywhere in the code or use Babel.  &lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  ES6 ?
&lt;/h2&gt;

&lt;p&gt;Having support for es6 modules means that you could do the following:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Stuff, {some, other, stuff} from 'some/library';
export thing;
export default anotherThing;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This breaks the monotony of &lt;code&gt;require()&lt;/code&gt; and IMO, this is a much cleaner syntax. Earlier, if you wanted to do this, you had to&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;use TS (which although can be a good thing, adds an extra 'build' step before execution and while this pattern might suffice for frontend development, it's a completely show-killer for me.)
&lt;/li&gt;
&lt;li&gt;use the Babel library that 'transpiles' your es6 code to it's equivalent commonJS code.
&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;Note that although these statements are supported, currently they map to their &lt;code&gt;require()&lt;/code&gt; and &lt;code&gt;module.exports&lt;/code&gt; equivalents in node, so doing essentially the same thing as Babel, but with no extra dependencies. &lt;br&gt;
Also, using &lt;code&gt;import&lt;/code&gt; and &lt;code&gt;export&lt;/code&gt; is the correct way forward, because at some point of time in future, node is going to adopt this way of using modules and not completely relying on &lt;code&gt;require()&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
Also, did I mention that using &lt;code&gt;import&lt;/code&gt; and &lt;code&gt;exports&lt;/code&gt; is faster than &lt;code&gt;require()&lt;/code&gt; ?  :)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Let's start the code now.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Setup
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;h3&gt;
  
  
  Note
&lt;/h3&gt;

&lt;p&gt;This tutorial will guide you in making a simple, barebones node app with es6 support. I will not be including any other stuff like express, extra dependencies etc. for the sake of simplicity.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Do a &lt;code&gt;npm init&lt;/code&gt; to get the basic package.json:  &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "name": "es6-api",
  "version": "1.0.0",
  "description": "es6-api",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" &amp;amp;&amp;amp; exit 1"
  },
  "keywords": [
    "es6",
    "api"
  ],
  "author": "",
  "license": "ISC"
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now, we need to add a few things to &lt;code&gt;package.json&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To add support for ES6 modules, add the line &lt;code&gt;"type": "module"&lt;/code&gt; to your &lt;code&gt;package.json&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Add a &lt;code&gt;"dev"&lt;/code&gt; script in the &lt;code&gt;"scripts"&lt;/code&gt; property like: &lt;code&gt;"dev":"node --es-module-specifier-resolution=node src/index.js"&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Change &lt;code&gt;"main": "index.js",&lt;/code&gt; to &lt;code&gt;"main": "src/index.js",&lt;/code&gt; make a folder src and touch a file &lt;code&gt;index.js&lt;/code&gt; in it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your &lt;code&gt;package.json&lt;/code&gt; should look like this now:&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2FugMz-G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a7giig6pvcwrbtwe3vqh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2FugMz-G--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/a7giig6pvcwrbtwe3vqh.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;npm install eslint &amp;amp;&amp;amp; npx eslint --init&lt;/code&gt; in the root dir (where package.json is stored) to setup eslint.&lt;br&gt;&lt;br&gt;
Answer all the questions according to your choice. Make sure to set the option 'What type of modules does your project use?' to 'esm'. These were my choices, but yours might differ:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zSJyMUtM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cjbiy7i8m5y55cqlrkr4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zSJyMUtM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/cjbiy7i8m5y55cqlrkr4.png" alt="Alt Text"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;It will write the config to &lt;code&gt;.eslintrc.json&lt;/code&gt; in the root dir and install a local copy of eslint in the &lt;code&gt;node_modules&lt;/code&gt; directory.&lt;br&gt;&lt;br&gt;
Open &lt;code&gt;.eslintrc.json&lt;/code&gt; and you should see the config similar to this:&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HPYP3_z---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/192m1gih4fx1b4y7lbmp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HPYP3_z---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/192m1gih4fx1b4y7lbmp.png" alt="Alt Text"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Now here, we need to make some changes to make eslint work with our esm setup.&lt;br&gt;&lt;br&gt;
First, add the line &lt;code&gt;"es6": true&lt;/code&gt; to the &lt;code&gt;"env"&lt;/code&gt; porperty value. Then, make a new property called &lt;code&gt;"globals"&lt;/code&gt; and add the following line in it's value: &lt;code&gt;"__dirname": true&lt;/code&gt;. This we'll come to this later in the code.&lt;br&gt;&lt;br&gt;
The config should look like this now:&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--H1Sllhvl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1ehre2k2pzi6w8jsayj9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--H1Sllhvl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/1ehre2k2pzi6w8jsayj9.png" alt="Alt Text"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Now that eslint is setup, we can go ahead and edit the &lt;code&gt;src/index.js&lt;/code&gt; file. Add the following code to it:  &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// src/index.js

import path from 'path';

global.__dirname = path.resolve('./');
console.log(__dirname);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This code will do 2 things:  &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Verify that we can in fact, use &lt;code&gt;import&lt;/code&gt; statement.&lt;/li&gt;
&lt;li&gt;In node with esm, variables like &lt;code&gt;__dirname&lt;/code&gt; which are normally availabe in the global scope, are undefined. These 2 statements make it available in the global scope again. Notice that we also added the line &lt;code&gt;"__dirname": true&lt;/code&gt; in &lt;code&gt;.eslintrc.json&lt;/code&gt;. Without that, eslint will give an error saying that __dirname is not defined.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now that our starter code is ready, return to the root dir and run &lt;code&gt;npm run dev&lt;/code&gt;. You should get the following output:&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YlGjz_mZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y4tfrgq8r9en2qjbtyrc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YlGjz_mZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y4tfrgq8r9en2qjbtyrc.png" alt="Alt Text"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;h2&gt;
  
  
  Exporting stuff
&lt;/h2&gt;

&lt;p&gt;Let's look into making our own modules and exporting stuff.&lt;br&gt;&lt;br&gt;
Start by making a directory &lt;code&gt;example&lt;/code&gt; in the &lt;code&gt;src&lt;/code&gt; directory. Touch a file index.js inside it and add the following code:  &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const value1 = 99;
const value2 = 100;

export { value2 };
export default value1;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;We're making a module here and exporting &lt;code&gt;value1&lt;/code&gt; as a default export and &lt;code&gt;value2&lt;/code&gt; as a named export. We will also import these values in the main index.js.&lt;br&gt;&lt;br&gt;
Replace the code of &lt;code&gt;src/index.js&lt;/code&gt; by:  &lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import path from 'path';
import value1, { value2 } from './example';

global.__dirname = path.resolve('./');
console.log(value1, value2);
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;By now, your project should like this:  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SRSZZVCU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ohg9o1nhdwixcs9v3q6o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SRSZZVCU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/ohg9o1nhdwixcs9v3q6o.png" alt="Alt Text"&gt;&lt;/a&gt;  &lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;npm run dev&lt;/code&gt; and you should see&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;gt; es6-api@1.0.0 dev /home/tushar/src/tmp/tut/es6-api
&amp;gt; node --es-module-specifier-resolution=node src/index.js

99 100
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;That confirms that our es6 module was loaded successfully in node without using babel!.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Footnotes
&lt;/h2&gt;

&lt;p&gt;You can go wild with esm by using &lt;code&gt;await import(...)&lt;/code&gt;, module-aliases, importing commonJS modules and much more, but I think that would be out of the scope of this article.&lt;br&gt;&lt;br&gt;
Also note that since &lt;code&gt;import&lt;/code&gt; as of now is identical to &lt;code&gt;require()&lt;/code&gt;, you can basically load data from a JSON file by writing &lt;code&gt;await import('file.json')&lt;/code&gt;.&lt;br&gt;&lt;br&gt;
If you liked this tutorial or have some suggestions, please drop a comment below. Thank you for reading. Bye and have a nice day.&lt;/p&gt;

</description>
      <category>es6</category>
      <category>node</category>
      <category>tutorial</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
