npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@gabriele-salvo/test

v2.0.0

Published

my first npm package

Downloads

2

Readme

ULTRA BASIC FIRST NPM PACKAGE

This npm package, takes 2 numbers and return its sum!!!! WOW

let's go through the process

1. Setup your project


mkdir my-cool-package
cd my-cool-package
npm init

The npm init command will ask you a series of questions (like package name, version, description, entry point, test command, git repository, keywords, author, license, etc.) and create a package.json file based on your answers. You can also run npm init -y to accept default values and create package.json automatically.

if you dont have node.js and npm, follow this link.

2. Write your code

Write the code for your package. Let's say you're making a simple utility to add numbers:

// index.js (this is the main file you specified during npm init)

function addNumbers(a, b) {
  return a + b;
}

module.exports = addNumbers;

3. Write tests

Writing tests for your package is a key part of the development process. It ensures that your code works as expected and helps prevent future changes from breaking existing functionality.

3.1 Install Jest


npm install --save-dev jest

3.2 Configure Jest

Create a jest.config.js file at the root of your project with the following contents for more complex configurations:

module.exports = {
  verbose: true,
  // other configuration options
};

3.3 Set up your tests

Create a test file next to the code that you want to test. By convention, Jest looks for test files with any of the following popular naming conventions:

Files with .js suffix in __tests__ folders.
Files with .test.js suffix.
Files with .spec.js suffix.

For example, if you have a file named index.js, you could create a file named index.test.js for your tests.

Let's:


mkdir __tests__
cd __tests__
touch index.test.js

Then we need to configure change a tiny bit the package.json by adding:


"scripts": {
  "test": "jest"
}

3.4 Write your tests

Here's an example of what your index.test.js might look like:

const addNumbers = require("../index");

test("adds 1 + 2 to be equal 3", () => {
  expect(addNumbers(1, 2)).toBe(3);
});

3.5 Run your Tests


npm test

3.5.1 Test Coverage (optional)

Jest can also check how much of your code is covered by tests. You can run Jest with the --coverage flag to enable this feature.


npm test -- --coverage

This will create a coverage report in the coverage/ directory of your project, which you can view in your browser.

3.5.2 Continuous Integration (Optional)

You can integrate Jest with continuous integration (CI) systems to run tests automatically when you push code changes. This can be configured using services like GitHub Actions, Travis CI, CircleCI, etc.

For next time 😉

4. Document Your Package

Create a README.md file explaining what your package does, how to install it, examples on how to use it, and any other information users might need.

5. Publish Your Package

Before publishing, make sure you have an account on npm. Once you have an account and are logged in to npm on your machine (npm login), you can publish your package:


npm publish

This is what you would normally do but we are learning here soooo

THIS IS WHAT WE ARE GOING TO DO

Let's change a bit out package.json like this:


"name": "package-name",

to


"name": "@username/package-name",

where username is the one you use to npm login and remember to do the same in the package-lock.json

Finally we can publish using:


npm publish --access public

6. All Done!

gif