You have encountered this error because your directory does not contain package.json file.
You can fix it by running only one command that is npm init. This command will create the required file for you.
npm init