-2

sometimes I get confused what is the differences between npm init and git init when I want to start a project. I do not know where and when I should use each of them?

Can I use them together or I should use them separately?

Should I use them just at the start of the project or I can use them anytime?

Ellie
  • 41
  • 5
  • 7
    Are you clear on the purposes of Git as a source control system and Node Package Manager (NPM) as a package manager for configuring a project and third party libraries and how those two things are distinct and separate? – crashmstr Jun 23 '21 at 11:55
  • @crashmstr if I was clear, I would not ask! – Ellie Jun 23 '21 at 12:58

2 Answers2

1

Source control (Git in this case, but there are other systems) is used to track and preserve history of source code changes over time.

Pro Git Book

A package manager (NPM in this case, but there are others like nuget), help one manage and include third party libraries into ones code. In the case of NPM specifically, it also may contain scripts or configuration that declares information about your project, like name, version, description, and where, online, your code is hosted (i.e. its source control).

About NPM

So to answer your question about when they should be used:

  • Git should generally be used for most projects
  • NPM should be used when you need to include third party libraries you want to use from the NPM repository.
crashmstr
  • 28,043
  • 9
  • 61
  • 79
  • To this, one might add: if you're writing a node package that stands alone, you'd run `git init` to create the version-control-management directory and then start writing and committing the project code. If you're writing a node package that needs *other* node packages too, you'd still start with `git init`, but as you write your code, when you get to the point where you need to incorporate someone else's code, *then* you'd run `npm init`. – torek Jun 23 '21 at 20:02
0

Description. npm init can be used to set up a new or existing npm package. initializer in this case is an npm package named create- , which will be installed by npx , and then have its main bin executed -- presumably creating or updating package.

///////////////////////Git init //////////////////////////////////// The git init command creates a new Git repository. It can be used to convert an existing, unversioned project to a Git repository or initialize a new, empty repository. Most other Git commands are not available outside of an initialized repository, so this is usually the first command you'll run in a new project.

////////////////////////////////////////////////////////////