The `touch` package for Node.js provides a cross-platform implementation of the Unix `touch(1)` command, enabling programmatic modification of file access and modification times, or the creation of new, empty files. Its current stable version is 3.1.1. The package offers both asynchronous (Promise-based and callback-based) and synchronous APIs, including `touch()`, `touch.sync()`, `touch.ftouch()`, and `touch.ftouchSync()`. A key differentiator is its dual API for file path and file descriptor manipulation, alongside a `nodetouch` CLI executable that mirrors the native `touch` utility. Release cadence is not explicitly stated, but the package maintains a stable API and provides consistent functionality across Node.js versions, focusing on reliable file system interaction.
npm install touchVerified import paths — ran on the pinned version, not inferred.
Demonstrates both asynchronous (Promise-based) and synchronous usage of the `touch` library to create files and update their timestamps, including specific modification times.
Explicitly set `atime: false` or `mtime: false` if you intend to only update one timestamp, or pass a specific `Date` object to the desired option.
Choose either callback-based or Promise-based error handling and success notification consistently. Avoid providing a callback if you intend to `await` the Promise or use `.then().catch()`.
Ensure the Node.js process has appropriate file system permissions for the target path. Run the application with elevated privileges if necessary (e.g., `sudo node app.js`) or change directory/file permissions using `chmod`.
Verify and adjust file/directory permissions for the user running the Node.js application. On Unix-like systems, `chmod` or `chown` can be used. Consider running the process with appropriate user privileges.
Ensure you are importing the module correctly: `const touch = require('touch')` for CommonJS or `import touch from 'touch'` for ESM. Verify that `touch` is the default export and its methods are accessed correctly.Provide a valid `Date` object, a string parseable by `Date.parse()` (e.g., ISO 8601 format), or an epoch millisecond number for time options.
No dependency data recorded yet.