Vasanth Srivatsa Profile picture
Tech Lead at @IntrobotAI with a decade of programming experience & a passion for technology.

Apr 26, 2021, 10 tweets

Here's an marvelous ๐Ÿงต thread on โงฉ

Beginners ๐Ÿ“– Guide To โœจ Publishing JavaScript Projects ๐ŸŸ On @npmjs

#100DaysOfCode #JavaScript #TypeScript #CodeNewbie

Continue reading ๐Ÿ‘‡

แ‰ Deciding Package Name

Finding the right name for your project plays a key role in making it discoverable

It should be ๐Ÿ‘‡

๐Ÿ”น Available on GitHub & NPM
๐Ÿ”ธ Short and rememberable
๐Ÿ”น Relevant to the purpose

For the purpose of this thread, I am using a random word "integrated"

แ‰ Creating package.json

Create a new directory and run "npm init -y" in it. This will create a basic package.json file.

Open this file in your favorite code editor and fill in the license, description, and author fields.

๐Ÿ‘‡

แ‰ During Development

While you're working on making your project come to life, keep the version to 0.x.x.

This will ๐Ÿ‘‡

๐Ÿ”น Indicate that it's in development
๐Ÿ”ธ Lets you push breaking changes

แ‰ Writing Code

You can make a cli app or, a library that runs in the browser or Node.js.

For example, I'll make an app.js and module.export a simple console.log.

Whatever you export from this app.js (or so-called entryfile) will be accessible to users of your library.

๐Ÿ‘‡

แ‰ Setting Project Type

We need to tell npm where is code for our project.

To do that ๐Ÿ‘‡

๐Ÿ”น Open package.json
๐Ÿ”ธ For lib, add a key "main" and set it to the path of entryfile
๐Ÿ”น For cli, add a key "bin" and set it to the path of executable
๐Ÿ”ธ Adding both is also supported

๐Ÿ‘‡

แ‰ Login To npmjs

It's time that we publish our project to @npmjs ๐Ÿ™Œ

Run "npm login" and put in your username, password, and public email address.

This will link npm cli with your npmjs account.

If you don't have an account, creating one is pretty easy!

๐Ÿ‘‡

แ‰ First Publish

Let's do it! ๐Ÿค˜ Run the command "npm publish".

This will publish your JavaScript project to npm.

Now anyone can use your project by running ๐Ÿ‘‡
npm install <project_name>

You'll also get a lovely ๐Ÿ’– email from npm that it's published.

๐Ÿ‘‡

แ‰ Adding Keywords

Once your project is ๐Ÿฅณ published. Time to spread the word about your project!

Re-open package.json & fill the keywords from similar packages. That will get let your project come on searches ๐Ÿš€

Keywords show during searches & on your package page on npm

๐Ÿ‘‡

Special โœจ thanks to @AyushCodes for giving me the idea ๐Ÿ’ก

Thank you so much! ๐Ÿ™ for reading. If you can follow me, and retweet ๐Ÿ”„ this thread to your developer gang, it would be impressive ๐Ÿคฉ

๐Ÿ‘‡

Share this Scrolly Tale with your friends.

A Scrolly Tale is a new way to read Twitter threads with a more visually immersive experience.
Discover more beautiful Scrolly Tales like this.

Keep scrolling