Research
Security News
Kill Switch Hidden in npm Packages Typosquatting Chalk and Chokidar
Socket researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Unique filenames with streams support
Checking if a file exists before opening is an anti-pattern that leaves you vulnerable to race conditions: another process can remove the file between the calls to fs.exists() and fs.open(). This functions doesn't use fs.exists functionality. If file doesn't exist this will work like usual fs module methods
npm install fsu
Same as fs.open but open for writing and creates unique filename.
const fsu = require('fsu');
fsu.openUnique("text{_###}.txt", (err, fd, path) => {
//now we can use file descriptor as usual
});
Same as fs.writeFile but creates unique filename.
const fsu = require('fsu');
fsu.writeFileUnique("text{_###}.txt", "test", (err, path) => {
console.log("Done", path);
});
Same as fs.createWriteStream but returns writable stream for unique file.
const fsu = require('fsu');
let stream = fsu.createWriteStreamUnique("text{_###}.txt");
Stream has a path
property that contains a new path
Add force = true
to options, and it will recursively create directories if they are not exist.
You must use {#}
pattern in filename and path. All #
characters will be change with counter for existing files. Number of #
means padding for unique counter. With no pattern in the filename works as usual 'fs' module.
If we run second example several times filenames will be
text.txt
text_001.txt
text_002.txt
License: MIT
FAQs
Unique file name with streams support
The npm package fsu receives a total of 0 weekly downloads. As such, fsu popularity was classified as not popular.
We found that fsu 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 researchers found several malicious npm packages typosquatting Chalk and Chokidar, targeting Node.js developers with kill switches and data theft.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.