Eduard Neculaesi

Publishing my first npm package

So today was a good day! I published my first npm package. I’ll admit, it’s not the best package out there but I’m happy with what I have until now and I had the chance to learn how to publish a package to the npm registry.

The package is called connect-routing and, as you can tell from the name, is a connect routing middleware. Check out the package here or view the source code here

But I’ll stop there as this blog post is about npm and how you can publish your own package.

Npm

Npm stands for node package manager, and as the name says it’s a package manager used mostly for node modules. To publish you own node module you need to start by having a package.json file.

package.json

This file is used to add certain metadata to your package like version, name, description but also to define dependencies and the main file for running your package.

The four needed properties are name, version, author and main.

Great so now that we have the final source for our project and a minimal package.json what do we do?

npm adduser

Next up we need to have a user registered, so to do that we use npm adduser. This will prompt us for a username, password and an email address that will be public.

npm publish

This is the final step to getting that magic squirrel on npm. What this will do is read the package.json in the current folder and upload all the files/folders in there to the npm registry.

That’s it, you’re done, your magic squirrel is in the wild making the world a better place.

Some tips and tricks

  1. Have a README file and make sure you have a minimal documentation in there. Don’t let people figure out on their own how to use you package.
  2. Use .npmignore to choose what files and folders are published and installed. By default npm will use .gitignore, if available, but the files you want to publish may be different to those you want to ignore in git.
  3. Make sure your library works before publishing. You can make a test project and installing your package from a local folder (npm install ../path/to/your/project) and trying it out.

Final words

So, as you can see, it’s not that hard to have your own package published to npm. I hope you will start writting open source libraries and publish them. Have fun coding!

P.S: Questions? Want to have a chat? Send me an email at neculaesi.eduard@gmail.com and tell me more.

Hello, there!

Hi there! My name is Eduard Neculaesi, but you can call me Ed or Eddie. I am a front-end developer with a passion for everything technical or beautiful. This is the first post of many, I hope, focused on technologies, gadgets and maybe other subjects I find interesting.

Why blogging?

This is my fourth attempt to start a blog and I think I finally realized where I went wrong with the previous ones. I always thought blogging is about sharing amazing, never before seen stuff, then I read some great articles (found by just searching ‘why start a blog’ on Google) that opened my eyes and taught me that blogging is about sharing your thoughts, your opinion, opening ways for conversation and, possibly, meeting new people.

OK, what’s it about?

Well, I will write about tech stuff. Maybe my opinion on a newly released gadget or a new framework or a programming language. I will, possibly, have a series of articles about something I’m currently learning as this would be helpful to me and, maybe, others.

What’s next?

I’m not sure what my next post will be about, I’m still planning my posts and I have many drafts but make sure to push the follow button and you will surely hear from me soon.

Thanks for reading this and if you have any questions, please add them in the comments section below or if you just want to talk send me an email at neculaesi.eduard@gmail.com