How to do it...

If we've just signed up for an npm account (as explained in the Getting ready section), we'll want to authorize our npm client with npmjs.org.

On the command line, we simply need to run this:

npm login 

Then, supply the username, password, and email address we signed up with.

Every module should have a README explaining how it works.

Let's create a Readme.md file with the following markdown:

# hsl-to-hex

Convert HSL colors to RGB colors in hex format.

## Install

```sh
npm install --save @davidmarkclements/hsl-to-hex
```

## API

```
require('hsl-to-hex') => Function
hsl(hue, saturation, luminosity)` => String
```

## Example

```js
var hsl = require('hsl-to-hex')
var hue = 133
var saturation = 40
var luminosity = 60
var hex = hsl(hue, saturation, luminosity)
console.log(hex) // #70c282
```

## License

ISC

In the install section of the readme, we should replace @davidmarkclements with our own username.

Markdown
Markdown is a lightweight documentation syntax; refer to https://guides.github.com/features/mastering-markdown/.

As a courtesy, we'll also take the example we wrote in the Readme and put it in an example.js file.

Let's create a file called example.js with the following content:

var hsl = require('./')
var hue = 133
var saturation = 40
var luminosity = 60
var hex = hsl(hue, saturation, luminosity)
console.log(hex) // #70c282

Note how we've made a minor adjustment to the example code; instead of requiring hsl-to-hex, we're requiring ./. This ensures that the example.js file will run.

Now, we'll make some final touches to the package.json file.

First, we'll reinitialize the module:

npm init 

Following this command, we can simply press Enter in response to all questions. The output of npm init should show that a description field has been added, with its content taken from the Readme.md file:

"description": "Convert HSL colors to RGB colors in hex format.",

Now, let's open the package.json file and change the name field by prefixing it with an at (@) symbol, followed by our npm username, followed by a forward slash (/). Consider the following instance:

"name": "@davidmarkclements/hsl-to-hex",  

Of course, instead of using @davidmarkclements, we'll use whatever username we supplied to npm login.

Extra Credit - Push to GitHub
If we follow the Reinitializing portion of the There's more section in the Scaffolding a module recipe, we can also take this opportunity to push to GitHub just before we publish. This can be useful in helping users explore code and clone our repo to execute the example, run tests, or even fix bugs or add features, which can be contributed back to our module.
To do this, we can run
git add .
git commit -m 'v1.0.0'
git push.

Finally, we're ready to publish:

npm publish --access=public 

We should now be able to navigate to https://www.npmjs.com/package/@davidmarkclements/hsl-to-hex  (where @davidmarkclements is the username we're using) and view the module's npm page: