loading...
Cover image for Why publishing your own npm packages can make you a better developer

Why publishing your own npm packages can make you a better developer

thegeoffstevens profile image Geoff Stevens Updated on ・6 min read

There are many great resources about how to publish your own npm packages, but I want to share a few thoughts on why you should be publishing your own npm packages and why it will make you a better developer.

If you are looking for a technical overview of building npm packages, Dan Vega wrote a particularly thorough post about publishing your first npm package. I would highly recommend that any beginners read Dan’s guide.

First, what is an npm package?

npm is a tool that provides Node.js and JavaScript developers with a quick and simple way to install, share, and manage npm packages. npm packages are modules created by the community that help developers greatly extend the functionality of their JavaScript applications.

For example, the popular request package enables developers to make http calls by simplifying the functions needed to handle all the complexities of http calls into easy-to-use methods.

npm packages are most often hosted by npm Inc through its npm registry. The npm registry serves as a public collection of packages of open-source code for Node.js, front-end web apps, mobile apps, robots, and many other needs of the JavaScript community.

npm website screenshot: "build amazing things"

Interestingly, using npm packages is a critical part of building extensions for Visual Studio Code. As the creators of a VS Code extension, Code Time, we have benefited greatly from the vibrant JavaScript ecosystem. We have also recently begun building a few packages of our own—our latest creation, cody-music, is a music module that can control a user’s Spotify and iTunes apps.

In the process of building our own npm packages and Visual Studio Code extensions, we have learned quite a bit about how to integrate npm packages into the development process and why publishing our own packages has made us better developers. Below are a few of the lessons we have learned.

Easily showcase your developer skills

Developers are builders, constantly starting new projects, trying new technologies, and contributing to community initiatives. For many developers, building a portfolio is an important way to showcase the skills and abilities they have honed over time.

During their careers, developers are likely to work on projects that are intertwined with other projects. npm packages, however, can be standalone snippets of your work that you will be able to quickly and easily share with colleagues, employers, and friends.

User profile on the npm registry

Building and sharing your own npm package with the community is a great way to demonstrate your JavaScript and programming skills. Since npm packages can be as complex or simple as you want them to be, you can leverage your entire breadth of knowledge as a developer.

Not only will you be able to demonstrate your programming skills, you will also have the opportunity to showcase your ability to write documentation that is easy to read and understand. npm packages are publicly available to the developer community, so you will be responsible for packaging your module for use by other developers.

Communication is an invaluable skill for developers of all backgrounds.

Learn how to build something that others can use

Many of my personal side projects are horrifying examples of spaghetti code. When writing code for myself, it is tempting to cut corners and fall into bad habits. Even my own code is illegible to me if I revisit a project after not looking at it for a while.

To build something that any developer in the world can use is a rare, yet powerful, opportunity. And with great power comes great responsibility.

npm package stats

As other developers find your project, you will need to learn how to write clear and concise documentation. You will also need to organize your project on GitHub, or another repository hosting service, so that any potential contributors or curious developers will be able to peruse your code. You will wrestle with how to best name your functions so that others can understand how they work.

By building an npm, you will walk a mile in the shoes of another developer. You will begin to understand how someone else will view your project. In the process, you will become a smarter developer who is better attuned to the needs of the community around you.

Learn how to take a software project from ideation to release

Individual developers who are looking to take ownership of a project will learn a lot from designing their own npm package. Building an npm package requires you to oversee the entire product development cycle, from ideation to public release and beyond.

At each point in the cycle, you will be exposed to new challenges and unique learning opportunities. You will juggle everything from architecture planning to pull request reviews. You become a manager for your own mini-product.

npm packages offer the perfect combination of scale and power. Building an npm is not so complex and overwhelming that you will be unable to finish, yet the final product will have the potential to help a whole community of developers.

Give back to the open source community

Open source software is the lifeblood of the software development world. Even so, contributing to open source projects can often be intimidating, especially for beginners.

Finding a project you would like to contribute to, perusing contribution guidelines, submitting pull requests for maintainers to review—the entire process can feel a bit overwhelming at times.

If you are looking for an easier way to give back to the open source community, publishing an npm package is a great opportunity for beginners and experienced developers alike. npm packages can be as simple or as complex as you want them to be. No project is too small to have an impact.

npm ecosystem at a glance

And JavaScript is THE most popular programming language, so you will discover a number of great resources to help you along your learning journey. Backed by a growing ecosystem of JavaScript tools, you should be confident that you can make a difference in the community.

Become part of a community and get valuable feedback

Once your npm package is publicly available, other developers are likely to have feedback or suggestions. Ideally, some developers will even submit pull requests to your project on GitHub.

Interacting with the development community and learning how to incorporate feedback will help you hone your leadership and project management skills.

Moment package on GitHub

Suggestions from other developers will also help you become a better developer by exposing you to new and better development practices or tools that you can then carry over to any other projects you may be working on. Pull request reviews and issue discussions are wonderful opportunities to learn from the community.

Modularize your code for a cleaner codebase and better tests

Application architecture can get messy, fast. Writing tests for complicated code is, unsurprisingly, also complicated. Code often involves many moving pieces that can get tangled in unforeseen ways by unsuspecting developers.

Abstracting parts of your code and organizing them into modular npm packages will declutter your codebase and help you better leverage reusable code across different parts of your application. Code can be quickly shared between team members, and redundant instances of functions can be eliminated. The result is a cleaner and more manageable codebase.

Modular code also enables modular testing. By separating your code into packages, you can write and execute reproducible tests to ensure that each package is functioning as expected. Most npm packages are built so that anyone can install and run tests that are included with the package. As a developer, you will write better tests by maintaining close proximity between your tests and the original code, as npm packages require you to do.

With npm packages to abstract your application’s reusable functionality, you will add structure and organization to your code that will streamline your development process.

See the power of the npm package

Creating and publishing your own npm can be a rewarding experience for any developer of any skill level. By learning how to build your own open source product and managing its release to the developer community, you will supercharge your developer skill set.

For development teams, modularizing your code into individual packages can accelerate development by standardizing some of the processes needed to manage your code. npm packages streamline the entire build, test, and deploy workflow—a big benefit for your team to use and reuse throughout your codebase and for the open source community at large.

Don’t miss out on our code editor plugin Code Time and our developer newsletter SRC. Thanks for reading!

Discussion

pic
Editor guide
 

This is great stuff, I even checked out the previously linked article too!

What types of things would you create npm packages for? I've only used them in regards to tutorials.

I guess it can be anything? Genuine newbie here!

 

Great article, which is interestingly published on the same date with my very first npm package :)

npmjs.com/package/react-omni-counter

 

Awesome! Looks useful, I'll check it out.

 

Great article. I enjoyed reading it. It made me rethink my workflow for better testing.

 

Most of this article seems like it could apply to any package system, not just npm. If anyone has only ever done JavaScript, it's definitely worth exploring other languages/ecosystems too.

 

I am always discovering the magic of coding!

 

Yay. I created best ever normalization utility. Normalizr alternative thanks to this article github.com/pavliha/normalize-api