<?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: sijils</title>
    <description>The latest articles on DEV Community by sijils (@sijils).</description>
    <link>https://dev.to/sijils</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%2F245838%2F3d68149b-0001-4423-acc2-22b3e39bdc3d.png</url>
      <title>DEV Community: sijils</title>
      <link>https://dev.to/sijils</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sijils"/>
    <language>en</language>
    <item>
      <title>Publishing npm package to Github package repository</title>
      <dc:creator>sijils</dc:creator>
      <pubDate>Wed, 09 Oct 2019 04:13:02 +0000</pubDate>
      <link>https://dev.to/sijils/publishing-npm-package-to-github-package-repository-5ane</link>
      <guid>https://dev.to/sijils/publishing-npm-package-to-github-package-repository-5ane</guid>
      <description>&lt;p&gt;Github package repository is where you can publish npm, gem, mvn, nuget, gradle, docker packages and is currently now in beta. In this tutorial, we will see how we can publish an npm package to the github package respository. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Code the node.js project you want to publish as npm module in github repo. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create a github repository in which you will be publishing the package.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After you have done the programming for the node.js project, modify the name field and add the fields bin, repository and publishConfig to the package.json as shown below.&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@github_user/npm_module_name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;bin&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;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;cli_command_name&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./&amp;lt;name_of_the_index_script&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;repository&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;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;git&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;url&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;&amp;lt;git_repo_link&amp;gt;&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;publishConfig&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;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;registry&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://npm.pkg.github.com/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;cli_command_name&lt;/em&gt; is the cli command for invoking your module. &lt;em&gt;name_of_the_index_script&lt;/em&gt; is the script that will be called when &lt;em&gt;cli_command_name&lt;/em&gt; is invoked. It is the main script in your project.  &lt;em&gt;git_repo_link&lt;/em&gt; is the git repo you have created for publishing the npm module. &lt;em&gt;npm_module_name&lt;/em&gt; is the name of the npm module to be published.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Login to the github npm registry from the console using the below command
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    npm login --registry=https://npm.pkg.github.com --scope=@github_user
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;github_user&lt;/em&gt; is the username of your github account.&lt;br&gt;
Executing this query will ask for username and password. Username is your github username. Password is Personal Access Token which can be generated from your github account settings page.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Run &lt;em&gt;npm publish&lt;/em&gt; command from the project directory. This will publish your node.js project as npm module to github repository. The github repository link is &lt;em&gt;git_repo_link/packages&lt;/em&gt; . The module will be published in the scoped mode.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A git push will push the project to the git repo mentioned in the package.json file, &lt;em&gt;git_repo_link&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the module can be installed by anyone from this repository. To do this, the user who intends to install the module should set the npm registry in .npmrc file as &lt;em&gt;registry=&lt;a href="https://npm.pkg.github.com/github_user"&gt;https://npm.pkg.github.com/github_user&lt;/a&gt;&lt;/em&gt; . Once this configuration is done, the npm module can be installed by running the command &lt;em&gt;npm install @github_user/npm_module_name&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can find my github repo and github npm module at &lt;a href="https://github.com/sijils/resume"&gt;https://github.com/sijils/resume&lt;/a&gt; and &lt;a href="https://github.com/sijils/resume/packages"&gt;https://github.com/sijils/resume/packages&lt;/a&gt; respectively for reference.&lt;/p&gt;

</description>
      <category>github</category>
      <category>npm</category>
      <category>career</category>
      <category>resume</category>
    </item>
  </channel>
</rss>
