Writing module code
In this recipe, we’re going to start writing our module code. The module we will write will expose two APIs that will be used to convert the supplied temperature from Fahrenheit to Celsius and vice versa. We’ll also install a popular code formatter to keep our module code consistent and add some simple test cases.
Getting ready
Ensure you’re in the temperature-converter
folder and that package.json
is present, indicating that we have an initialized project directory.
We’ll also need to create the first JavaScript file for our module:
$ touch index.js
Later, we’ll try testing importing and using the module, so let’s create two files ready for that:
$ touch test.js
How to do it…
We’re going to start this recipe by installing a code formatter to keep our module code styling consistent. By the end of this recipe, we will have created our first Node.js module.
- First, let’s add...