Initialize a Node.js Project with NPM

Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

The first step to creating your project is initializing with NPM. We will walk through all the options that NPM has for you to create a package.json and also show you a shortcut to accept all the default options with the -y flag.

Kevin Cunningham: [0:00] I find myself in a new terminal window with a directory for my application called quizme. At the moment, this is a completely empty directory with nothing in it. I want to initialize my new Node project. I'm going to do that with npm init. [0:13] Npm init runs a utility program that creates our package.json file which tells users about the dependencies that our package has, some scripts, and other metadata around our package. I'll start off with the package name.

[0:28] The default option is the name of the directory we're in. I'm in a directory called quizme and the default option is to call the package quizme. I'm going to press Enter to accept that.

[0:38] Then we have a version. Again, we've got a default option in parentheses, which you could press Return to be able to accept, or you could add the version you want to add instead. Description can be left blank, but I'm going to add this as an "Application for spaced repetition."

[0:57] Entry point is the file that if other people are importing your package, they'll be able to use. In this case, I'm going to leave it as index.js, which is the default value.

[1:06] Test command, it's what I would run in order to execute the test. I don't have my test set up, so I'll leave this blank. If this is associated with a GIT repository. At the moment it's not, so I'll press Return.

[1:18] The keywords, I'm going to press Return again and the license. In this case, I've got MIT as my default options or other three options, like BSC. You can decide which license you want.

[1:29] I did get the prompt that's about to write this, the package.json, and an export of what that might look like. I'm happy with that, so I'll press Enter for yes.

[1:37] If I check my directory now, I have a single file, package.json, which has the same contents as were sent up above. I'm going to remove my package.json file. I'm going to run npm init again, but this time I'm going to parse the flag -y, which is going to accept all the default options and create my package.json file as well.

[1:59] If you'd like to create your package quickly, you can run npm init -y to be able to create that default [inaudible] or without the -y you can have the prompts to be able to add and update the file as it's created.

egghead
egghead
~ 33 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today