Creating a Silly Name Generator with an NPM Package — A Step-by-Step Guide

Hasini chamodi
LinkIT
Published in
3 min readMay 18, 2024
image source:https://www.freecodecamp.org/news/what-is-npm-a-node-package-manager-tutorial-for-beginners/

Prerequisites

Before we get started, make sure you have the following prerequisites in place​:​

  1. Node.js: Ensure you have Node.js installed on your computer. To check this run the following command on your command prompt or terminal.

if it’s installed, This command will display the installed Node.js version as above. If Node.js is not installed, it will return an error. You can download it from the official website and install it.

2. NPM: Node.js comes with NPM (Node Package Manager) pre-installed.

Step 1: Create a New Node.js Project

Let’s start by creating a new Node.js project. Open your terminal or command prompt and navigate to the directory where you want to create your project. Then, run the following commands:

This will create a new directory for your project and generate a ‘package.json’ file with default settings.

Step 2: Install the “sillyname” NPM Package

The “sillyname” package is a fun library that generates random, silly names. Install it in your project by running the following command:

This will add the “sillyname” package as a dependency in your ‘package.json’ file.

You can verify the package you intend to install by visiting its official website and consulting the documentation for detailed instructions on its usage.

source:https://www.npmjs.com/

Step 3: Create Your Silly Name Generator Script

Now, let’s create a JavaScript file that will contain the code for our silly name generator. You can name this file something like ‘sillyname-generator.js’ Open your text editor and add the following code:

This code imports the “sillyname” package, generates a random silly name using the package, and then prints it to the console.

Step 4: Run Your Silly Name Generator

To run your silly name generator, execute the following command in your terminal:

Now you should see a random silly name printed to the console each time you run the script. Feel free to run it multiple times to see different names.​👩‍💻😇

--

--