Setting up a Node project - OpenZeppelin Docs (original) (raw)

JavaScript software is often bundled in packages, which are distributed via the npm registry. A package is simply a directory that contains a file called package.json, describing the package’s name, version, content, and others. When you build your own project, you will be creating a package, even if you don’t plan to distribute it.

All Node installations include a command-line client for the npm registry, which you’ll use while developing your own projects. To start a new project, create a directory for it:

$ mkdir learn && cd learn

Then we can initialize it:

Simple as that! Your newly created package.json file will evolve as your project grows, such as when installing dependencies with npm install.

| | JavaScript and npm are some of the most used software tools in the world: if you’re ever in doubt, you’ll find plenty of information about them online. | | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |

Using npx

There are two broads type of packages stored in the npm registry: libraries and executables. Installed libraries are used like any other piece of JavaScript code, but executables are special.

A third binary was included when installing node: npx. This is used to run executables installed locally in your project.

Whilst Hardhat can be installed globally we recommend installing locally in each project so that you can control the version on a project by project basis.

For clarity we’ll display the full command in our guides including npx so we don’t get errors due to the binary not being in the system path:

$ hardhat init
hardhat: command not found
$ npx hardhat init
👷 Welcome to Hardhat v2.22.12 👷‍
? What do you want to do? …

| | Make sure you are inside your project’s directory when running npx! Otherwise, it will download the full executable again just to run that command, which most of the time is not what you want. | | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |