Node.js – ENOENT: No Such File or Directory Error

node.jsnpm

 C:\Users\shagy\Desktop\3RD YEAR 2ND SEMESTER\SPM\Newfolder\SPM-SMS>npm start 
npm ERR! path C:\Users\shagy\Desktop\3RD YEAR 2ND SEMESTER\SPM\New folder\SPM-SMS\package.json npm ERR! code ENOENT
npm ERR! errno -4058 
npm ERR! syscall open 
npm ERR! enoent ENOENT: no such file or directory, open 'C:\Users\shagy\Desktop\3RD YEAR 2ND SEMESTER\SPM\New folder\SPM-SMS\package.json' 
npm ERR! enoent This is related to npm not being able to find a file. 
npm ERR! enoent
npm ERR! A complete log of this run can be found in: npm ERR!   C:\Users\shagy\AppData\Roaming\npm-cache\_logs\2018-09-05T14_23_49_736Z-debug.log

How to resolve this issue? Even after npm install, this error is showing up

Best Answer

This is related to npm not being able to find a file. The error-message npm ERR! enoent is telling you that the file can't be found.

First check if the file actually exists on your fs under that path and check the reference-path you use to call that file for possible typos.

If this is a fresh project you can call

npm init 

and node will initliaize your project and create a package.json for you..

From the official docs:

Description: npm init can be used to set up a new or existing npm package.

initializer in this case is an npm package named create-, which >will be installed by npx, and then have its main bin executed -- presumably >creating or updating package.json and running any other initialization-related >operations.

The init command is transformed to a corresponding npx operation as follows:

  • npm init foo -> npx create-foo
  • npm init @usr/foo -> npx @usr/create-foo
  • npm init @usr -> npx @usr/create

Any additional options will be passed directly to the command, so npm init foo --hello will map to npx create-foo --hello.

If the initializer is omitted (by just calling npm init), init will fall back to legacy init behavior. It will ask you a bunch of questions, and then write a package.json for you. It will attempt to make reasonable guesses based on existing fields, dependencies, and options selected. It is strictly additive, so it will keep any fields and values that were already set. You can also use -y/--yes to skip the questionnaire altogether. If you pass --scope, it will create a scoped package.

For more detailed information please read the official docs about npm init.

Related Question