<?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: Moein Hosseini</title>
    <description>The latest articles on DEV Community by Moein Hosseini (@rxmoein).</description>
    <link>https://dev.to/rxmoein</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%2F208957%2F51f928ac-176d-4710-afd5-00badb546fb1.jpg</url>
      <title>DEV Community: Moein Hosseini</title>
      <link>https://dev.to/rxmoein</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rxmoein"/>
    <language>en</language>
    <item>
      <title>How To Create and Use Private NPM Packages</title>
      <dc:creator>Moein Hosseini</dc:creator>
      <pubDate>Wed, 03 Mar 2021 14:41:11 +0000</pubDate>
      <link>https://dev.to/rxmoein/how-to-create-and-use-private-npm-packages-5f5e</link>
      <guid>https://dev.to/rxmoein/how-to-create-and-use-private-npm-packages-5f5e</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;This post was originally published on my blog&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Packages, packages everywhere, big or small pieces of code that make development way easier and fast. Sometimes we use a prepared package developed by other members of the community, and sometimes we create a package for ourselves. Maybe you are working in a company and want to create an npm package for your team or simply you are just trying to make a piece of code reusable in more than one project. It's a good choice but there's a question. How can I use and install that package without putting it up on the npm public registry? Let's figure it out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create your first NPM package
&lt;/h2&gt;

&lt;p&gt;Starting a new package is just as easy as starting a new javascript project. we are going to call our package "legendary" Open your terminal and run this command to create a folder for our legendary package and go into that directory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir &lt;/span&gt;legendary &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;cd &lt;/span&gt;legendary
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we initialize a new &lt;code&gt;package.json&lt;/code&gt; by running this command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will be asked some questions like the package name, version, license and etc. Answer them and then go to the next step. The result will be a &lt;code&gt;package.json&lt;/code&gt; with contents similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"legendary"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"description"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"A legendary package"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"main"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;Error: no test specified&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt; &amp;amp;&amp;amp; exit 1"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Moein Hosseini"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"license"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ISC"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Write package code and add a private field
&lt;/h2&gt;

&lt;p&gt;Now it's time to add some code to our library. As you saw on our &lt;code&gt;package.json&lt;/code&gt; file, it will be named &lt;code&gt;index.js&lt;/code&gt; because that's our main file. The code can be a simple function like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hello from legendary package.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we should remember to add the &lt;code&gt;private&lt;/code&gt; field in &lt;code&gt;package.json&lt;/code&gt; file. When you set it to &lt;code&gt;true&lt;/code&gt;. Npm will refuse to publish it on npm and prevents your code from being published accidentally on the npm public registry.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"private"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Private npm registry
&lt;/h2&gt;

&lt;p&gt;If you have more than one packages and more than one user you might need to have a private npm registry. There are some options out there like the npm proxy registry that you can publish your private packages on a private server.&lt;/p&gt;

&lt;h3&gt;
  
  
  Publish package on a private registry
&lt;/h3&gt;

&lt;p&gt;To publish your package in a private registry you must have a user on it and log in using the npm command-line interface&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm login &lt;span class="nt"&gt;--registry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://mysecretregistry.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point you are logged into your private registry and can publish your package but what do we mean by our package? What files should be included in this library? You can specify them by adding a field named &lt;code&gt;files&lt;/code&gt; in the &lt;code&gt;package.json&lt;/code&gt; file. For my legendary package, I have &lt;code&gt;index.js&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"files"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="s2"&gt;"index.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally to publish your npm package use the below command. This command publishes the package with the specified version number in the &lt;code&gt;package.json&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm publish &lt;span class="nt"&gt;--registry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://mysecretregistry.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Install package from private registry
&lt;/h3&gt;

&lt;p&gt;Installing a package from private is just like the regular ones with specifying the registry address:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;legendary &lt;span class="nt"&gt;--registry&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://mysecretregistry.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Static package files
&lt;/h2&gt;

&lt;p&gt;You always don't need a private registry. It cost's a lot and also you don't want to put it on the registry while you are the only user for that package. So there is a better way. Just run the following command to generate a static compressed file that can be installed by npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm pack
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The result will be a file named &lt;code&gt;legendary-1.0.0.tgz&lt;/code&gt;. Take this file to any directory you want and install it by just giving the file address to npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; /some/dir/legendary-1.0.0.tgz
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now import your legendary library and use it in as many projects as you want.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>npm</category>
      <category>package</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Why Side Projects Are Important For Developers</title>
      <dc:creator>Moein Hosseini</dc:creator>
      <pubDate>Tue, 02 Mar 2021 19:28:48 +0000</pubDate>
      <link>https://dev.to/rxmoein/why-side-projects-are-important-for-developers-4ifh</link>
      <guid>https://dev.to/rxmoein/why-side-projects-are-important-for-developers-4ifh</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xtsvbOIS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49fjg4slx5dujoe78tex.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xtsvbOIS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/49fjg4slx5dujoe78tex.png" alt="Side Projects" width="880" height="531"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This post was originally published on &lt;a href="https://moein.blog/2021/02/why-side-projects-are-important-for-developers/"&gt;my blog&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It doesn't matter if you are a junior or senior software developer. There is always a thing that you might have missed and haven't learned it. Depending on our field, we all have different experiences, therefore we can use the same tools in different ways to solve a business problem.&lt;/p&gt;

&lt;p&gt;The thing is we will not completely learn how to use a tool if we don't use that tool for more variant problems in even different industries with  brand new perspective.&lt;/p&gt;

&lt;p&gt;Imagine you are a front-end developer (maybe you are), you are so good at your work using a popular framework or library. What if someone told you I need a charting system with custom rendering engine? or what if you were supposed to create javascript package to solve a problem? So if you didn't know much about javascript module systems, Since now you need to learn it better with more details and extend you domination over your current tool, javascript. &lt;/p&gt;

&lt;h2&gt;
  
  
  More development experience
&lt;/h2&gt;

&lt;p&gt;Side projects gives you more experience with the programming language you are working with and there are lot's of possibilities that you might forget to experience. This is a great chance to extend your domination over your current programming tools.&lt;/p&gt;

&lt;p&gt;Also it's very good to sit down and think a little about your old solutions, reevaluate them and come up with a new better idea or solution. A solution needs to prove itself by passing some test after implementation. This is your side project, implement and use your new ideas to take your next project to the next level.&lt;/p&gt;

&lt;h2&gt;
  
  
  Exploring new features and technologies
&lt;/h2&gt;

&lt;p&gt;As a software developer you need to keep yourself updated about new things related to your job. You definitely can't achieve this buy reading random stuff from internet. Specially when the new things are happening about your current tools.&lt;/p&gt;

&lt;p&gt;To be always updated about your tools features you need to run some experiment, see how do they work and think about how can you use them to keep your software quality as high as possible.&lt;/p&gt;

&lt;p&gt;Side projects are the best way to try new technologies, services, frameworks and programming languages. The more you explore new technologies, the more you can provide better and efficient solutions to the problems. Problem solving is not just about solving problems, it's more about your perspective and how you see new challenges.&lt;/p&gt;

&lt;h2&gt;
  
  
  See different aspects of a software product
&lt;/h2&gt;

&lt;p&gt;Most of the time when we say side projects you might think of some small projects created to just practice your technical skills, but you can start a bigger project too, you can create, deploy and sell your products to real customers. This experience is so valuable that can change your vision about a software product.&lt;/p&gt;

&lt;p&gt;In a company depending on your role, you may be responsible for just the technical and development part but when you are selling your own product you'll face some new problems. Business needs, customer needs, marketing, devops and etc might be the thing that you never had too learn if you didn't start that side project. Maybe your current side project could also be your future main project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Opportunity to try different approaches
&lt;/h2&gt;

&lt;p&gt;When you create an almost big project you see things in a more abstract way, trying to figure out what's the best approach to solve business problems. Most of us at first are fighting with bugs and developing the projects. Development at first is about details and analyzing problems. But when it comes to business a vast perspective is a need.&lt;/p&gt;

&lt;p&gt;So a new thing to try is other programming and design paradigms. If you want to improve your skills, at some point you are going to learn software design and architecture too. Using the same paradigms over and over again may help you make the system work but is the system working with the best performance and complexity level? what will be the costs if you wanted to add a new feature to it?&lt;/p&gt;

</description>
      <category>programming</category>
      <category>sideprojects</category>
      <category>guide</category>
    </item>
  </channel>
</rss>
