How get absolute path for tmp folder in windows 10 and nodejs?

Viewed 3799

I am trying to ru the following code (tmp lib here):

const tmp = require('tmp')
tmp.dir(async (err, path, cleanupCallback) => {
    console.log(path)
}

Which outputs:

C:\Users\LONGUS~1\AppData\Local\Temp\tmp-13152HMljuIU3YKR0

How to make it output real path, like that C:\Users\LONGUSERNAME\AppData\Local\Temp\tmp-13152HMljuIU3YKR0?

1 Answers

The tmp package uses os.tmpdir() internally as the base path, which on Windows returns the TEMP, TMP, or (systemRoot + ''\\temp'') directory paths.

The TEMP environment variable on Windows always defaults to using the DOS 8.3 "short" style path as a legacy for backwards compatibility with older software dating back to Windows 9x.

You have a few options:

  1. Supply your own base path for the tmp Node module.
  2. Use another module to resolve the 8.3-style filename into the full path.
  3. Change the TEMP environment variable yourself to use the full path. You can do this on a per-process basis.
Related