Save time just like God, using npm

Michael Rybintsev
5 min readFeb 10, 2018

--

Creation myth is all about npm, for real!

Fear not — npm is here to help you. Most of the time.

I did notice that sometimes npm causes a lot of fear among the aspiring developers and think it shouldn’t be that way. Hopefully a short story will help understand the basics.

- What is npm and why should I use it?

npm is like a supermarket for developers. You go there to get yourself a meal. Imagine if you had to grow your veg, grow your meat, make your plates, it can get out of hand quickly and eventually you’ll settle down for some camp fired weird tasting sourbread and dirty water. Life needn’t be that difficult. So use npm to download your lasagna and go ahead, at the end of the day, you just want to have a nice evening. Although just like with horse meat in burgers and lasagna in the UK, you too should be careful with what you get with npm.

So in the rest of my article let me tell you an ancient story of a developer and his npm package.

First, he checked if the name is free…

$ npm view thebeginning

and got response

npm ERR! code E404
npm ERR! 404 Registry returned 404 for GET on https://registry.npmjs.org/thebeginning
npm ERR! 404
npm ERR! 404 'thebeginning' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/God/.npm/_logs/-3982-02-10T15_46_30_727Z-debug.log

Good, thebeginning name is not taken and so it started.

In thebeginning he used npm and package.json.

thebeginning

For npm has no limit to it, as he knew there is all sorts of things up there “in the cloud” and he heard that open-source is kind of good.

He opened his terminal in VS Code with “ctrl+`" and typed:

$ npm init

because package.json — is a fairly stable place and every project needs some firm ground to stand on.

The prompt appeared:

package name: (thebeginning)

pressed enter, as that was, indeed, the project name.

version: (1.0.0) 0.0.0

for semantic versioning is good — a prerelease version should not be 1.0.0.

description: ah, let's give this thing a go, see how it works outentry point: (index.js)test command:

He was not an experienced dev and just pressed enter on this one as he isn’t much into Test Driven Development. thebeginning project definitely matured him as it went on.

git repository:

He ignored this one. Very controversial, but look around — there is still no way to revert commits…

keywords: side-project giving-a-go learn-something-new hope-this-doesnt-tank

He knew that it would be a side project and knew that ‘npm search’ will help others have fun with his project if he uses searchable tags.

author: God

Because who else?

license: (ISC)

yeah, whatevs.

About to write to /Users/God/sideGigs/thebeginning/package.json:{
"name": "thebeginning",
"version": "0.0.0",
"description": "ah, let's give this thing a go, see how it works out",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"side-project",
"giving-a-go",
"learn-something-new",
"hope-this-doesnt-tank"
],
"author": "God",
"license": "ISC"
}
Is this ok? (yes)

yeah, kind of.

so now he has package.json

And the package.json was without form, and void; and darkness was upon the face of the deep. And he hovered his mouse over an empty project folder and was like “well, this VS Code theme is bloody good.” It’s Cobalt2 VS Code theme by Wes Bos — of course it’s amazing!

Then he said, “Let there be light”; and there was light.

npm install light --save

Because when anyone installs thebeginning, they won’t need to install light separately as it is a dependency.

And he saw that the light was good; and npm separated the light from the darkness into a separate node_modules folder.

Darkness and water come with thy OS.

... And there was evening and there was morning, the first day.

And he said,

npm install dome --save

“and let it separate the waters from the waters.”

Not in the scripture, but surely he must have:

npm i typescript --save-dev

for to control the chaos, one needs a statically typed language and it’s used as development dependency, because users won’t need it for usage.

So he made the dome and separated the waters that were under the dome from the waters that were above the dome. And it was so.

Declare thy types!

So he finished with the package.json

So all the dev-dependencies and dependencies are saved in node_modules, and package-lock.json was generated automatically.

And he wrote,

And it was so.

Next time an online course asks you to install a package — fear not! You’ve got a lesson from the creator himself.

PS. I think he didn’t publish thebeginning after all. If only he posted us on github and got a few stars from friends and his colleague developers, then maybe the story would’ve been different. But it also seems like he is very protective — the second rule in the readme basically says “You shall have no other gods before me”, so don’t think he was pro-open-source.

If you enjoyed this story, please click the 👏 button and share to help others find it. Feel free to leave a comment.

You can also follow me on Twitter: Michael Rybintsev.

If you’ve spotted an error or know how to improve the article — please drop me a line.

Disclaimer: The above story was intended for entertainment/education purposes and is not for any other use. If you don’t think so, please accept my sincere insouciance.

--

--