Getting npm ENOENT Error when I run “npm install express” command

The Problem:
I recently bought the new M2 MacBook Pro and installed NodeJS but I can’t install any packages in the project folder. When I run the “npm install express” command I get this output in Terminal:

    npm ERR! code ENOENT
    npm ERR! syscall mkdir
    npm ERR! path /path-to-tmp
    npm ERR! errno -2
    npm ERR! enoent ENOENT: no such file or directory, mkdir '/path-to-tmp'
    npm ERR! enoent This is related to npm not being able to find a file.
    npm ERR! enoent 
    
    npm ERR! Log files were not written due to an error writing to the directory: /path-to-tmp/_logs
    npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

When I run the command with the –-loglevel-verbose tag I get this output:

    npm verb cli /usr/local/bin/node /opt/homebrew/bin/npm
    npm info using [email protected]
    npm info using [email protected]
    npm verb cache could not create cache: Error: ENOENT: no such file or directory, mkdir '/path-to-tmp'
    npm verb logfile could not create logs-dir: Error: ENOENT: no such file or directory, mkdir '/path-to-tmp'
    npm verb title npm install express
    npm verb argv "install" "express" "--loglevel" "verbose"
    npm verb logfile logs-max:10 dir:/path-to-tmp/_logs/2023-03-25T12_46_53_501Z-
    npm verb logfile could not be created: Error: ENOENT: no such file or directory, open '/path-to-tmp/_logs/2023-03-25T12_46_53_501Z-debug-0.log'
    npm verb logfile no logfile created
    npm verb stack Error: ENOENT: no such file or directory, mkdir '/path-to-tmp'
    npm verb cwd /Users/USER_NAME/Desktop/Test
    npm verb Darwin 22.3.0
    npm verb node v19.8.1
    npm verb npm  v9.5.1
    npm ERR! code ENOENT
    npm ERR! syscall mkdir
    npm ERR! path /path-to-tmp
    npm ERR! errno -2
    npm ERR! enoent ENOENT: no such file or directory, mkdir '/path-to-tmp'
    npm ERR! enoent This is related to npm not being able to find a file.
    npm ERR! enoent 
    npm verb exit -2
    npm verb unfinished npm timer command:install 1679748413521
    npm verb unfinished npm timer reify 1679748413523
    npm verb unfinished npm timer reify:loadTrees 1679748413543
    npm verb unfinished npm timer idealTree 1679748413543
    npm verb unfinished npm timer idealTree:buildDeps 1679748413547
    npm verb unfinished npm timer idealTree:#root 1679748413547
    npm verb code -2
    
    npm ERR! Log files were not written due to an error writing to the directory: /path-to-tmp/_logs
    npm ERR! You can rerun the command with `--loglevel=verbose` to see the logs in your terminal

Running just node install returns normal output to the terminal and I had run npm init previously and have a package.json file in the project folder. My active directory in terminal was the project folder when I ran these commands.

Operating System and Programs:

  • macOS Ventura 13.2.1
  • ZSH terminal shell version: 5.8.1
  • Node Version: 19.8.1
  • NPM Version: 9.5.1

Debugging Steps I’ve Taken:

  1. Added .zshrc file and ensured /usr/local/bin is in my $PATH
  2. Tried using sudo in conjunction with npm install
  3. Tried manually creating the /path-to-tmp folder in the / directory though this failed because the / directory is strictly Read permissions for all users
  4. Edited folder permissions for the “Test” folder to make all users have Read Write Access
  5. Uninstalled and reinstalled Node along with trying to use both Homebrew and website to install with
  6. Deleted package-lock.json and retried running node install