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.
exports all fs.promises + exists + mkdirp + rmrf + getFiles + getDirs functions.
be in a nodejs project
npm install @magic/fs
import fs from '@magic/fs'
const run = async () => {
await fs.mkdirp('./test_235235/dir/to/create')
console.log('dir created')
await fs.rmrf('./test_235235')
console.log('dir deleted, even though it had contents.')
}
run()
promises from fs:
access
copyFile
open
opendir
rename
truncate
rmdir
mkdir
readdir
readlink
symlink
lstat
stat
link
unlink
chmod
lchmod
lchown
chown
utimes
realpath
mkdtemp
writeFile
appendFile
readFile
exists
readDir
readfile
rmDir
rmdir, rmDir
readfile, readFile
readdir, readDir
same as mkdir -p on unix
await fs.mkdirp('./path/to/dir')
same as rm -rf on unix.
will not work outside process.cwd()
await fs.rmrf('./path/to/dir')
same as fs.exists, but promisified and ready for esmodules.
get a list of directories in a directory, recursively.
import fs from '@magic/fs'
const run = async () => {
// first level directories
const directories = await fs.getDirectories(process.cwd(), false)
console.log(directories)
// first level again
const dirs = await fs.getDirectories(process.cwd(), { depth: false })
// recursive run
const deepDirectories = await fs.getDirectories(process.cwd())
console.log(deepDirectories)
// recursive run with specified depth
const deepDirectoriesDepth2 = await fs.getDirectories(process.cwd(), { depth: 2 })
console.log(deepDirectoriesDepth2)
// use /some/dir as root instead of process.cwd()
const deepDirWithRoot = await fs.getDirectories(process.cwd(), { depth: true, root: '/some/dir' })
console.log(deepDirWithRoot)
}
run()
get a list of files in a directory, recursively.
import fs from '@magic/fs'
const run = async () => {
// first level directories
const files = await fs.getFiles(process.cwd())
console.log(files)
// recursive run
const deepFiles = await fs.getFiles(process.cwd(), { depth: true })
console.log(deepFiles)
// recursive run with specified depth,
const deepFilesDepth2 = await fs.getFiles(process.cwd(), { depth: 2 })
console.log(deepFilesDepth2)
}
run()
get the file type of a file, based on extension, and defaulting to "txt"
import fs from '@magic/fs'
const fileType = fs.getFileType('html.html')
console.log(fileType, fileType === 'html')
const nonFileType = fs.getFileType()
console.log(nonFileType, nonFileType === 'txt')
first release
better error messages
rmrf returns true if directory does not exist.
use @magic/mime-types to export contentTypes
bump required node version to 14.2.0
rmrf: add dryRun option
update dependencies
// if a number is given instead of true/false, then this is the depth of recursion.
getFiles(directory, 2) // two levels down
update dependencies (@magic/mime-types)
export all functions from native fs
update dependencies (@magic/mime-types)
update @magic/types to avoid circular dependency
add deprecation warning for calls to fs.getDirectories, fs.getFilePath and fs.getFiles that do not use an options object
update dependencies
update mime-types
update dependencies
update dependencies
update dependencies
update dependencies
getFiles: allow files to be filtered by extension, using the .extension key of the second parameter
update dependencies
update dependencies
update dependencies
...
FAQs
nodejs fs promises + goodies
The npm package @magic/fs receives a total of 339 weekly downloads. As such, @magic/fs popularity was classified as not popular.
We found that @magic/fs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.