Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Tempy is a utility package for creating temporary files and directories. It provides a simple API to generate temporary paths, files, and directories that are automatically cleaned up when no longer needed.
Create a temporary file
This feature allows you to create a temporary file. The `tempy.file()` method generates a unique file path in the system's temporary directory.
const tempy = require('tempy');
const tempFilePath = tempy.file();
console.log(tempFilePath);
Create a temporary directory
This feature allows you to create a temporary directory. The `tempy.directory()` method generates a unique directory path in the system's temporary directory.
const tempy = require('tempy');
const tempDirPath = tempy.directory();
console.log(tempDirPath);
Create a temporary file with a specific extension
This feature allows you to create a temporary file with a specific extension. The `tempy.file({ extension: 'txt' })` method generates a unique file path with the specified extension in the system's temporary directory.
const tempy = require('tempy');
const tempFilePath = tempy.file({ extension: 'txt' });
console.log(tempFilePath);
Create a temporary directory with a specific name
This feature allows you to create a temporary directory with a specific name. The `tempy.directory({ name: 'my-temp-dir' })` method generates a unique directory path with the specified name in the system's temporary directory.
const tempy = require('tempy');
const tempDirPath = tempy.directory({ name: 'my-temp-dir' });
console.log(tempDirPath);
The 'tmp' package provides similar functionality for creating temporary files and directories. It offers more control over the lifecycle of temporary files and directories, including the ability to set custom cleanup callbacks.
The 'fs-extra' package extends the native Node.js 'fs' module with additional methods, including methods for creating temporary files and directories. It is a more general-purpose file system utility library compared to tempy.
The 'temp' package is another utility for creating temporary files and directories. It provides a simple API and automatic cleanup, similar to tempy, but with a focus on ease of use and minimal configuration.
Get a random temporary file or directory path
npm install tempy
import {temporaryFile, temporaryDirectory} from 'tempy';
temporaryFile();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/4f504b9edb5ba0e89451617bf9f971dd'
temporaryFile({extension: 'png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/a9fb0decd08179eb6cf4691568aa2018.png'
temporaryFile({name: 'unicorn.png'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/f7f62bfd4e2a05f1589947647ed3f9ec/unicorn.png'
temporaryDirectory();
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/2f3d094aec2cb1b93bb0f4cffce5ebd6'
temporaryDirectory({prefix: 'name'});
//=> '/private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T/name_3c085674ad31223b9653c88f725d6b41'
Get a temporary file path you can write to.
The callback
resolves with a temporary file path you can write to. The file is automatically cleaned up after the callback is executed. Returns a promise that resolves with the return value of the callback after it is executed and the file is cleaned up.
Type: (tempPath: string) => void
A callback that is executed with the temp file path. Can be asynchronous.
Type: object
You usually won't need either the extension
or name
option. Specify them only when actually needed.
Type: string
File extension.
Type: string
Filename. Mutually exclusive with the extension
option.
Get a temporary directory path. The directory is created for you.
The callback
resolves with a temporary directory path you can write to. The directory is automatically cleaned up after the callback is executed. Returns a promise that resolves with the return value of the callback after it is executed and the directory is cleaned up.
Type: (tempPath: string) => void
A callback that is executed with the temp directory path. Can be asynchronous.
Type: Object
Type: string
Directory prefix.
Useful for testing by making it easier to identify cache directories that are created.
You usually won't need this option. Specify it only when actually needed.
Write data to a random temp file.
Write data to a random temp file. The file is automatically cleaned up after the callback is executed. Returns a promise that resolves with the return value of the callback after it is executed and the file is cleaned up.
Type: string | Buffer | TypedArray | DataView | stream.Readable
Data to write to the temp file.
Type: (tempPath: string) => void
A callback that is executed with the temp file path. Can be asynchronous.
See options.
Synchronously write data to a random temp file.
Type: string | Buffer | TypedArray | DataView
Data to write to the temp file.
See options.
Get the root temporary directory path. For example: /private/var/folders/3x/jf5977fn79jbglr7rk0tq4d00000gn/T
FAQs
Get a random temporary file or directory path
The npm package tempy receives a total of 8,489,558 weekly downloads. As such, tempy popularity was classified as popular.
We found that tempy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.