How to create package.json fast (skip the questions)

You can create your package.json file quickly, by automatically answering yes to all the questions during the setup. Run this command for either npm or yarn (in your project’s root directory):

## NPM
npm init -y

## Yarn
yarn init -y

In a couple of seconds, your package.json file is created, and you can begin to install dependencies and configure it to your needs.

This is my default way of creating package.json, because I often need to test something out quickly (like an npm package) that I probably won’t use in production. This shortcut init -y is a huge time saver.

What’s the downside of this approach?

There’s no downside.

The questions you skip or rather say yes to, are things like project name, version, and author. You can always fill out the questions later (inside the package.json file) if you end up using your project in production.


Has this been helpful to you?

You can support my work by sharing this article with others, or perhaps buy me a cup of coffee 😊

Kofi

Share & Discuss on