<?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: Sebastian Hoitz</title>
    <description>The latest articles on DEV Community by Sebastian Hoitz (@sebastianhoitz).</description>
    <link>https://dev.to/sebastianhoitz</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%2F544582%2F67a6853d-2875-4021-a326-470f53a85f1d.jpeg</url>
      <title>DEV Community: Sebastian Hoitz</title>
      <link>https://dev.to/sebastianhoitz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sebastianhoitz"/>
    <language>en</language>
    <item>
      <title>How to sell an npm package: A Guide</title>
      <dc:creator>Sebastian Hoitz</dc:creator>
      <pubDate>Thu, 03 Jun 2021 13:08:42 +0000</pubDate>
      <link>https://dev.to/sebastianhoitz/how-to-sell-an-npm-package-a-guide-2dn9</link>
      <guid>https://dev.to/sebastianhoitz/how-to-sell-an-npm-package-a-guide-2dn9</guid>
      <description>&lt;p&gt;When I quit the last company I was working at to pursue my own business adventures, building and selling a starter template or software library was high on my list of things I wanted to do.&lt;br&gt;
However, when I started to think about how I could actually do this, I realized there are not a lot of tools available that do a good job at this. Gumroad is a provider used by many creators, but not well suited for code. Other services target nodejs/npm only and leave out all the rest of the programming languages. So I figured out: I need to scratch my own itch and build this service first. Similar to Gumroad, but laser-focused on developers. Talk about niching down! And just like that, the idea for basetools was born.&lt;/p&gt;

&lt;p&gt;In this guide, I would like to show you how quickly you can start selling your own npm packages or other code.&lt;/p&gt;

&lt;p&gt;It is very easy to start selling an npm package using basetools. However, there are some prerequisites to start selling: You have to have a private Github repository inside an organization and you have to publish your package using the Github registry. But we will cover all of this within this guide.&lt;/p&gt;
&lt;h2&gt;
  
  
  Set up the repository
&lt;/h2&gt;

&lt;p&gt;For this guide, we will create a brand new repository on Github and start from there. If you have already created a repository, you can just skip this step.&lt;br&gt;
For our example, we are creating a new private repository within our organization &lt;code&gt;basetools-io&lt;/code&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%2F1y9ziby59tku3oifjw6q.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%2F1y9ziby59tku3oifjw6q.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this case, our new repository is called &lt;code&gt;basetools-npm-showcase&lt;/code&gt;. So let's get started on your machine:&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;basetools-npm-showcase
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"# basetools-npm-showcase"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; README.md
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;'module.exports = () =&amp;gt; console.log("hello world")'&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; index.js
git init
git add README.md index.js
git commit &lt;span class="nt"&gt;-m&lt;/span&gt; &lt;span class="s2"&gt;"first commit"&lt;/span&gt;
git branch &lt;span class="nt"&gt;-M&lt;/span&gt; main
git remote add origin git@github.com:basetools-io/basetools-npm-showcase.git
git push &lt;span class="nt"&gt;-u&lt;/span&gt; origin main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have now created a private repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup the package.json
&lt;/h3&gt;

&lt;p&gt;Next, we need to initialize the package.json, so that our repository can be treated as an npm package. We can easily do this by calling npm init. Important: Our package name has to contain our organization name. So instead of &lt;code&gt;basetools-npm-showcase&lt;/code&gt; we have to call our package &lt;code&gt;@basetools-io/basetools-npm-showcase&lt;/code&gt;. Make sure to commit the package.json to your repository.&lt;/p&gt;

&lt;h3&gt;
  
  
  Publish the package to your Github registry
&lt;/h3&gt;

&lt;p&gt;In order to always publish this package to the Github registry, you have to configure the npm registry in your package.json:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"publishConfig": {
  "registry":"https://npm.pkg.github.com"
},
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You also have to log in with your Github account. To do that, first generate a personal access token here: &lt;a href="https://github.com/settings/tokens" rel="noopener noreferrer"&gt;https://github.com/settings/tokens&lt;/a&gt;. Make sure to activate the &lt;strong&gt;write:packages&lt;/strong&gt; permission. Copy the generated token. Now, back in the terminal type in&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://npm.pkg.github.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If this was successful, you can finally publish your package:&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Adding the product on basetools
&lt;/h2&gt;

&lt;p&gt;Once you have completed the steps above, you can create an account on basetools if you haven't done so yet. After registration click that you want to add a new product.&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%2Fihzogfxbancbnfgdt656.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%2Fihzogfxbancbnfgdt656.png" alt="Add the npm packlage as a product to basetools"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And just like that, you can start selling! basetools automatically creates a checkout page for you. You can link to this page from your website, for example. After a successful payment, your customer will be automatically invited to your repository as a collaborator. This will grant him access to the repository and the packages:&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%2Flpqv4r1ffv9s1nx6f7lg.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%2Flpqv4r1ffv9s1nx6f7lg.png" alt="Confirmation of a sale of your npm package"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to install the package as your customer
&lt;/h2&gt;

&lt;p&gt;Once your customer has bought access to your repository, he also has to log in to npm with the Github account that was used when buying your product:&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://npm.pkg.github.com &lt;span class="nt"&gt;--scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;@OWNER
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;@OWNER&lt;/code&gt; is the name of your repositories account, in our example &lt;code&gt;@basetools-io&lt;/code&gt;. When this was successful, the package can be installed like any other npm package:&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; @basetools-io/basetools-npm-showcase
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Did you like this guide? It was originally published on the &lt;a href="https://basetools.io/how-to/sell-an-npm-package" rel="noopener noreferrer"&gt;basetools.io website&lt;/a&gt;. If you would like to go ahead and give basetools a try, you can find out more information right here: &lt;a href="https://basetools.io/?ref=devto" rel="noopener noreferrer"&gt;https://basetools.io/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>npm</category>
      <category>node</category>
      <category>tooling</category>
      <category>marketplace</category>
    </item>
  </channel>
</rss>
