hello-world-tutorial-_-a-tutorial-on-how-to-create-a-npm-package.
v1.0.2
Published
create your first npm package!
Readme
How to Create Your First Hello World NPM Package
Creating your first npm package is easy and fun! Follow this step-by-step guide to get started.
Step 1: Set Up Your Project Folder
- Create a new folder for your project.
- Navigate into the folder using your terminal.
mkdir my-first-npm-package
cd my-first-npm-packageStep 2: Initialize Your Package
Run the following command to create a package.json file:
npm initYou'll be prompted to answer questions like package name, version, description, entry point, etc. You can press Enter to accept defaults or provide custom values.
Step 3: Write Your Code
Create an index.js file inside your project folder with the following content:
function helloWorld() {
console.log("Hello, World!");
}
module.exports = helloWorld;This simple function logs "Hello, World!" to the console.
Step 4: Test Your Code Locally
Run the following command in your terminal to test your code:
node index.jsYou should see "Hello, World!" printed in the console.
Step 5: Publish Your Package
Log in to npm using:
npm loginPublish your package using:
npm publish
Your package is now live on npm!
Step 6: Install and Use Your Package
To use your package in another project:
Install it via npm:
npm install <your-package-name>Require and use it in your code:
const helloWorld = require('<your-package-name>'); helloWorld();
Congratulations! You've created and published your first npm package!
