Published on

Where is my Truffle Apps package.json file


While updating a truffle app today I decided I wanted to add some Husky hooks to it as illustrated here. I wanted to do this to streamline the development process a bit and only allow commits of solidity contracts that compile without issues.

As part of this tutorial you need to install some npm dependencies but I noticed that truffle apps do not have a package.json by default. Truffle init outputs the following structure:

   -> contracts
      -> Migrations.sol
   -> migrations
      -> 1_initial_migration.js
   -> tests
   -> truffle-config.js

You will notice that there is no package.json anywhere.

Luckily this is easily resolved. Do the following:

  • Go to your project's root (i.e. where the truffle-config.js sits)
  • Run npm init
  • Follow the prompts
  • And voilà you should now have a package.json file