How to sell npm packages?
What if you built an amazing npm package — how would you monetize it?
Monetizing code has been a challenging problem to solve for most of the developers. We usually end up selling the code as a SaaS or end up distributing it via Zip files. But how can one sell an npm package that you built? That’s exactly what we are gonna discuss in this article and this opens up the concept of Code as a Service(or CaaS).
How to sell a npm package?
I have been researching on this topic for over 2 months now and could hardly find a platform that makes it easier for developers to sell paid npm packages. Finally, found a useful solution— PrivJs.com
One way of selling was to host a private npm registry where you could publish your package and provide access to only your customers. But this takes a lot of time and efforts to setup, especially handling payments and access control. PrivJs.com takes care of all this for you. So, lets find out how we could sell a npm package on PrivJs.
Step 1: Signup for a new account at https://app.privjs.com/signup
Step 2: Add the PrivJs registry to your project'spackage.json
file. This makes sure that your project doesn’t get published to npm’s public registry — thus allowing only your customers to access the package.
"publishConfig": { registry: "https://r.privjs.com" }
Step 3: In the terminal, login to PrivJs with the account you just created by running:
$ npm login --registry https://r.privjs.com
Step 4: Once you have successfully logged in, then you can go ahead and simply publish the package by running:$ npm publish
If the publish is successful, then you could see the package in your PrivJs dashboard — app.privjs.com.
Step 5: Configure & sell the package.
If you are a new user then you probably need to connect your stripe account before you can start selling the packages. Once you connect your stripe account then all you need to do is simply set the price for the package and set the package for sale.
Enter the price that you wish to sell, and click the save button.
Step 6: Share the package with your followers
Once you mark the package for sale, then it gets listed in PrivJs’s Explore page where any person could purchase your npm package. Also, you could simply copy & share the package URL directly among your followers.
That’s all you need to do. Once the user purchases the package, he would be given access to install the package. Now you must be curious how the users could install the package isn’t it? It’s very easy — let me show you.
Installing a package from Privjs
In order to install any package from PrivJs, the user needs to be logged in and must have purchased the package that he is trying to install.
Step 1: $ npm login --registry https://r.privjs.com
and enter username, password
Step 2: $ npm install <packagename> --registry https://r.privjs.com
That’s all. If the user has access to the package it would proceed with the installation. Otherwise, PrivJs would not allow the installation to proceed.
Impressive isn’t it? This is a fairly new concept, so I am sure you could be having a lot of questions & queries. I am still researching on topics related to monetization opportunities for opensource developers and would be writing articles regarding the same. If you have any questions or need any advice/clarity, feel free to drop a comment below.
Cheers!