Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 1046 of the free egghead.io lessons, plus get JavaScript content delivered directly to your inbox!

Existing egghead members will not see this. Sign in.

Add version control to npm packages using git init

0:57 JavaScript lesson by

npm packages almost always have a git repo tied to them for version control. We will start our package by initializing a git repository.

Get the Code Now
click to level up

egghead.io comment guidelines


npm packages almost always have a git repo tied to them for version control. We will start our package by initializing a git repository.

Kristian Mørch

What type of terminal (or command) are you using to show and edit files in the terminal.


Hi Kristian, thanks for watching. I'm using Vim which is a terminal editor:

In reply to Kristian Mørch
Kristian Mørch

I was wondering what command to select files. I will watch the course, thanks for the good course on npm. PS. -D is a shortcut for -save-dev.

In reply to Trevor

Let's run MPM install Jest, and then save that to our development dependencies. Now if we look inside of our package.JSON inside of the dev dependencies we have this new Jest package listed.

Now in our scripts we can use that. We have this test script defined which is just the default echo statement. Let's change that to run the Jest binary. Now when we run the test script, this Jest command is going to run. Let's go into our source directory and we want to test this file here.

I'm going to create an index.test.js file, and this .test.js extension is one of the patterns that Jest recognizes by default. Inside the file we could import our module which we'll call "sensitive words" from the sibling file. Because the sibling file is in the current directory and its named with an index.js, this single dot will find it.

Now we can write our test, so we'll say test. Then we'll need a description of the test as well as a function to run.

For the description right now let's check that it says, "Hello world." Now we can say, expect that when sensitive words is run that it gives us, "Hello world."

For another pane I can say, "MPM test," and our test is failing. If we scroll up it says that it's not saying, "Hello world." We expected "Hello world" and we got "Hello universe." Let's go check our source file, and our source file is saying, "Hello universe" currently. Let's change that to "Hello world," save the file. Now we can rerun our test script and it's parsing.

Let's go back to our package.JSON and underneath our test script let's make a new script called "Test watch." We can have this run the test script and parse it the watch flag, which is the option that Jest provides for automatically watching tests. Now we should be able to run MPM run test watch, and our tests are parsing as well as continuing to run.

If we go back to our test file and change "world" to be "universe" again, if we run this our tests will be failing. We can open up our source file and change the world to be universe as well, and save that. Now our tests are parsing again. Now we can run our tests in watch mode and have our source files and tests all working together.

Joel's Head
Why are we asking?