Home - Blog - Details

How to use Yarn with a self - hosted registry?

Luna Li
Luna Li
Luna is a marketing manager at the company. She is responsible for developing marketing strategies to promote the company's products. Her creative ideas and market insights help to increase the brand awareness of Guangdong Lianyi Textile Co., Ltd.

Hey there, fellow yarn enthusiasts and digital nomads who spend way too much time in terminal windows (we see you!) – let’s talk about something that’s been on both our minds lately: how to use Yarn with a self-hosted registry. Wait, before you zone out on “self-hosted” and “registry,” hear me out. I’m Mia, and I run this small but mighty yarn brand – yeah, the one you might’ve seen linked around for stuff like Camel Blend Yarn, 2/30 95% Cotton 5% Cashmere Blend, Soft Chunky Iceland Yarn For Knitting, Love & Rose Sweater Long Sleeve Christmas Sweater, and Mohair Blend Yarn. For years, I only sold yarn in physical stores and Etsy shops, but last year, we launched our own self-hosted registry for custom yarn projects, and let’s just say it’s been a game-changer for both my internal dev team (shoutout to Jake who fixes all our server weirdness at 2am) and our wholesale clients who build custom knitting tools for their customers.

Now, why even bother with a self-hosted registry when you can just use npm’s public registry or Yarn’s default? Good question. For us, it’s all about control. Our yarn blends are unique – the kind that doesn’t get sold on big public platforms because we source the camel fiber from small farms in Mongolia and the cashmere from our trusted partner in Nepal. We don’t want those recipes floating around where copycats can grab them. Plus, our clients – like that knitting supply company in Portland that makes custom sweater kits – need to pull exactly the specific yarn lots they’ve agreed on, not whatever public Yarn registry spits out. A self-hosted registry lets us lock in those details, and it’s way simpler to set up than you’d think, even if you’re not a full-time dev (I’m proof – I can barely install a new plugin without panic, but I got this working in a weekend).

First things first, let’s get your basics straight. You need Yarn 1.x or Yarn 3.x? Honestly, both work, but I’ve found Yarn 3 is way less finicky with self-hosted registries (no more weird “invalid registry” errors that make Jake send me a meme instead of fixing it). We use Yarn 2 (wait, no, Yarn 3 – they rebranded) for our internal projects, so that’s what I’ll walk through here, but I’ll drop notes for Yarn 1 too. The main tool you’ll need is a registry server – we use Verdaccio because it’s open-source, lightweight, and doesn’t require a degree in cloud engineering to set up. Some folks use Nexus or Artifactory, but Verdaccio’s free for small teams, which was perfect when we started. Also, you need a domain name or at least an IP address where your registry lives – we used a cheap VPS from a local provider (no fancy AWS stuff yet) because we don’t need millions of concurrent users.

Step 1: Set up your self-hosted registry. If you’re using Verdaccio, it’s super straightforward. First, install Node.js (duh, because Yarn runs on Node), then open your terminal and type npm install -g verdaccio. Once that’s done, just run verdaccio, and it spins up a local server on http://localhost:4873. But wait, if you want it accessible from other devices (like your client’s laptop), you need to edit the config file – that’s where you change the listen line to 0.0.0.0:4873 instead of localhost. We did that, then set up a reverse proxy with Nginx so we could use a custom URL, like registry.ab.com (fitting, right? Since our site is ab.com). That way, our clients don’t have to type an IP address; they just use our branded registry link. Pro tip: Turn on basic auth in Verdaccio – that way, only our wholesale clients can log in and pull our yarn packages. We don’t want random people pulling the Love & Rose Sweater yarn and mass-making knockoffs, after all.

Step 2: Configure Yarn to use your self-hosted registry. This is the part I messed up a lot at first, so pay attention. For Yarn 3, you need to update your .yarnrc.yml file (that’s a hidden file in your project folder). Open it and add these lines:
npmRegistryServer: "https://registry.ab.com"
unsafeHttpWhitelist:

  • "http://localhost:4873" # only if you’re using local for testing
    publishRegistry: "https://registry.ab.com"

Wait, the publishRegistry line is key because that tells Yarn where to upload new yarn packages (like our new Mohair Blend Yarn lot we just got in). If you skip that, when you try to publish, it’ll default to npm’s public registry, and we don’t want our secret blend recipes out there. For Yarn 1, it’s simpler – just run yarn config set registry https://registry.ab.com in your terminal, and that’s it. But with Yarn 1, you have to remember to add --registry when publishing, like yarn publish --registry https://registry.ab.com, which I always forget (hence why we switched to Yarn 3).

Step 3: Test pulling and pushing packages. Now that you’ve got your registry set up and Yarn configured, let’s make sure it works. First, create a test project – mkdir yarn-test, cd yarn-test, yarn init -y. Now, try to add one of our yarn packages, like Soft Chunky Iceland Yarn For Knitting. Wait, but since it’s in our self-hosted registry, you can’t just yarn add that name – you need to specify the registry. So run yarn add @ab/soft-chunky-iceland-yarn --registry https://registry.ab.com. If that works, great! If not, check if you’re logged in – Verdaccio requires auth, so you need to run yarn login, enter your username and password, and then it’ll let you access private packages. Then, test publishing a dummy package to make sure that works too. Create a new folder, yarn init -y, add a description like “Test custom yarn package”, then run yarn publish. If it publishes to your self-hosted registry instead of npm, you’re golden. When we did this, we thought we messed up at first because the package didn’t show up on npm, but Jake explained that Verdaccio only lists packages you upload there, so that’s exactly what we wanted.

Now, let’s talk about some common pitfalls we ran into, because nobody has time for that. First, SSL certificates – if you’re using HTTPS (which you should, never use HTTP for a registry), you need a valid SSL cert. We used Let’s Encrypt, which is free, and it worked for our VPS. Forgetting that makes Yarn throw a “self-signed certificate” error, and that’s a 20-minute Google rabbit hole (ask me how I know). Second, package scoping – we use scoped packages (@ab/package-name) because it keeps our yarn packages separate from public ones. If you don’t use scopes, you might have name collisions with public packages, and that’s a nightmare. Third, version pinning – this is huge for our business. When we publish a yarn lot, we use exact versions, like @ab/camel-blend-yarn@1.2.0, so our clients know exactly which fiber blend they’re getting. If someone runs yarn upgrade, they won’t accidentally pull a newer version that has a different ratio of camel to wool (we once had a client switch to a newer Cotton Cashmere Blend and it messed up their sweater pattern, so lesson learned).

Wait, let’s circle back to why this matters for you, not just me as a yarn supplier. If you’re a knitter who uses digital tools to track projects (like that app that lets you log yarn lots), or a developer building knitting inventory software, a self-hosted yarn registry lets you use our exact, custom yarn packages without relying on public registries that might change or remove packages. We’ve had knitters message us saying they used our Camel Blend Yarn package in their Ravelry projects, but now it’s gone because the public registry took it down for no reason – with a self-hosted registry, that never happens.

Also, let’s talk about scaling. When we started, our self-hosted registry only had 10 packages, but now we have over 50 different yarn lots, from the 2/30 95% Cotton 5% Cashmere Blend to the new Mohair Blend Yarn. Verdaccio handles it all, but if you ever need more, you can switch to Nexus or just upgrade your VPS. We haven’t had to do that yet, and our client load is growing steadily, so that’s a win.

Here’s a quick real example from our team: Last month, a custom sweater designer in Toronto wanted to use the Love & Rose Sweater pattern but with our Soft Chunky Iceland Yarn instead of their usual wool. They used our self-hosted registry to pull the exact yarn package, integrated it into their design tool, and were able to adjust the pattern’s stitch count based on the yarn’s gauge – all because the registry had the precise yarn data (fiber content, yardage, gauge) that our public Etsy listings don’t include. That’s the magic of this setup – it’s not just for storing files, it’s for storing all the metadata that makes yarn projects work.

ff979206e9e68f9baa946a44a0963a7Iceland Yarn

Before we wrap up, a few quick tips to make this run smooth. 1. Back up your registry regularly – we use a simple cron job that backs up the Verdaccio storage folder every night. 2. Add a .gitignore for your registry data if you’re using Git – you don’t want to accidentally commit your yarn packages to GitHub. 3. For development, use local tunneling (like ngrok) if you don’t want a permanent server – we tested this when we were setting up and it worked, but we switched to a permanent VPS because our clients need reliable access.

Now, if you’re a knitter, developer, or business looking to integrate custom yarn packages into your digital workflows – or even just grab some of our unique blends for your projects – we’d love to chat. We’re always open to partnering with folks who want to use our self-hosted registry or purchase our premium yarns like Camel Blend Yarn, 2/30 95% Cotton 5% Cashmere Blend, Soft Chunky Iceland Yarn For Knitting, Love & Rose Sweater Long Sleeve Christmas Sweater, or Mohair Blend Yarn. Reach out to our team to discuss wholesale orders, custom package publishing, or even just troubleshooting your self-hosted registry setup – we’ve been there, we know the headaches, and we’re happy to help.

Like this post, drop a comment if you have questions (I’ll answer every one, promise), and check out our yarn shop linked above for all your knitting needs. Happy coding (and happy knitting)!

References:

  • Verdaccio: Open-source lightweight node package registry (https://verdaccio.org)
  • Yarn 3 Documentation: Registry Configuration (https://yarnpkg.com/configuration/yarnrc#npmRegistryServer)
  • Node.js: Required runtime for Yarn and Verdaccio (https://nodejs.org)
  • Let’s Encrypt: Free SSL certificates for web services (https://letsencrypt.org)
  • Ravelry: Knitting and crochet project management platform (https://www.ravelry.com)

Send Inquiry

Popular Blog Posts