So where to start?
Depends on what you want to work on. But in any way, if you prefer an IDE over terminal work environments (vim, emacs), you could for example use Visual Studio Code (personal favorite), Atom, or WebStorm. You also need
node installed, as well as a package manager (
yarn). Yarn claims to be faster, more reliable and secure than npm. It's main different to npm was the lock file, which is essentially used to reconstruct/rebuild/resolve the exact project dependencies for your project.
The core of your project configuration is the
package.json file. It specifies every dependency your project is using, as well as configurations for testing, scripts and more. When you run
npm install in the root project folder, the process looks for the package.json file and resolves its dependencies. It puts them (as well as sub-dependencies) into a
node_modules folder in that same directory. You can add scripts to your package.json file, for example to start/test/deploy your project. Sometimes a
postinstall scripts-hook is necessary which you can also add there.
A good example for a scripts-hook is one that invokes a linter before each
git commit. On this way you always have correctly formatted code on your repository.
Other lifecycle scripts are
npm start or
npm test, which are not executed automatically on installation. Before you publish your project to the npm repository using
npm publish, you might find it necessary to run a linter to format your code and then run your tests.
If you see a caret
^ before a dependency in your package.json file, it means that the package install process may use any version that is compatible with the specified one. This is why there is a lockfile as mentioned before. When you build a library for people to use in their project / package.json, you don't necessarily want them to install dependencies that they need for development. Thats what the
devDependencies are for.
Local vs Global Dependencies
Dependencies can be installed globally or locally. The difference is that local dependencies only available in this project, and can be executed from the
node_modules/.bin/ folder. They are made available in the
PATH, so you can run them by name instead of pointing to that hidden binary folder:
|"format": "eslint . --fix"|
In this example,
npm run format invokes the
node_modules/.bin/eslint binary, which is a locally installed dependency. This has the advantage that all team members use the same specific version for that project.