{"id":14074,"library":"suf-node","title":"SUF Node Utility Functions","description":"suf-node is a lightweight collection of utility functions designed specifically for Node.js environments. It provides asynchronous, promise-based wrappers for common operations across console interaction, process execution, and file system management. Key functionalities include `readConsole` and `getYNAnswer` for interactive command-line interface (CLI) input, `Exec` for safely running shell commands, and `Walk` and `Exits` for directory traversal and path existence checks, respectively. Currently at version 1.3.3, this library maintains a focused release cadence, typically releasing new features or bug fixes as needed for its specific utility scope. Its primary differentiator is a simple, modern API built on Promises, making it well-suited for async/await patterns in contemporary Node.js applications, aiming to streamline common tasks without introducing heavy external dependencies. The project appears to be actively maintained, providing foundational utilities for Node.js projects.","status":"active","version":"1.3.3","language":"javascript","source_language":"en","source_url":"https://github.com/TheRealSyler/suf-node","tags":["javascript"],"install":[{"cmd":"npm install suf-node","lang":"bash","label":"npm"},{"cmd":"yarn add suf-node","lang":"bash","label":"yarn"},{"cmd":"pnpm add suf-node","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library primarily uses ES Modules. While CommonJS `require` might work in some setups, direct ESM import is recommended for type safety and modern Node.js environments. Since suf-node 1.x ships with TypeScript definitions, ESM is the canonical import style.","wrong":"const { readConsole } = require('suf-node');","symbol":"readConsole","correct":"import { readConsole } from 'suf-node';"},{"note":"Use named import for `Exec` function. The `Exec` function returns a Promise, so it must be `await`ed or chained with `.then()`.","wrong":"const Exec = require('suf-node').Exec;","symbol":"Exec","correct":"import { Exec } from 'suf-node';"},{"note":"`Walk` is a named export for file system traversal. Like other utilities in this library, it is asynchronous and returns a Promise.","wrong":"const Walk = require('suf-node').Walk;","symbol":"Walk","correct":"import { Walk } from 'suf-node';"}],"quickstart":{"code":"import { Exec, Walk, readConsole, getYNAnswer } from 'suf-node';\nimport path from 'path';\n\nasync function main() {\n  console.log('--- SUF Node Quickstart ---');\n\n  // Example 1: Read console input\n  console.log('\\nEnter your name:');\n  const name = await readConsole();\n  console.log(`Hello, ${name}!`);\n\n  // Example 2: Get Y/N answer\n  console.log('\\nDo you like Node.js? (Y/n)');\n  const likesNode = await getYNAnswer(true); // Default to true\n  console.log(likesNode ? 'Great!' : 'Oh well.');\n\n  // Example 3: Execute a shell command\n  try {\n    console.log('\\nExecuting `ls -l` in current directory:');\n    const { stdout, stderr } = await Exec('ls -l', { linkStdout: false });\n    if (stdout) console.log('Stdout:\\n' + stdout);\n    if (stderr) console.error('Stderr:\\n' + stderr);\n  } catch (error) {\n    console.error('Exec failed:', error);\n  }\n\n  // Example 4: Walk a directory\n  try {\n    console.log('\\nWalking current directory:');\n    const files = await Walk(process.cwd());\n    console.log('Files found:', files.slice(0, 5).map(f => path.basename(f)).join(', ') + (files.length > 5 ? '...' : ''));\n  } catch (error) {\n    console.error('Walk failed:', error);\n  }\n\n  console.log('\\n--- Quickstart complete ---');\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Demonstrates interactive console input, executing shell commands, and listing files in a directory using the promise-based `readConsole`, `getYNAnswer`, `Exec`, and `Walk` functions."},"warnings":[{"fix":"Always `await` calls to `suf-node` functions, or handle the returned Promise with `.then().catch()`.","message":"All utility functions in `suf-node` are asynchronous and return Promises. Forgetting to use `await` or `.then()` will result in Promises not being resolved, leading to unexpected behavior or unhandled promise rejections.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your Node.js project is configured for ESM (e.g., `\"type\": \"module\"` in `package.json`) or use a transpiler like Babel/TypeScript to convert to CommonJS if necessary. Explicitly import named exports: `import { funcName } from 'suf-node';`.","message":"The library is primarily designed for ES Modules (ESM). Older Node.js projects using CommonJS (`require`) might encounter issues with default or named exports if their `package.json` `type` field is not set to `module`, or if they are running an older Node.js version.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Sanitize all user-provided input before passing it to `Exec`. Consider using Node.js's built-in `child_process.execFile` or `child_process.spawn` for better control and security when executing commands from external input, or use a command-line argument parsing library if user input specifies options.","message":"The `Exec` function runs arbitrary shell commands. Directly passing untrusted user input to `Exec` can lead to command injection vulnerabilities, allowing attackers to execute arbitrary code on your system.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.3.3':74 'across':30 'activ':134 'aim':119 'api':103 'appear':131 'applic':118 'async/await':113 'asynchron':22 'base':25 'bug':87 'built':104 'cadenc':81 'check':69 'cli':51 'collect':11 'command':48,58 'command-lin':47 'common':28,122 'consol':31 'contemporari':116 'current':71 'depend':128 'design':15 'differenti':98 'directori':64 'environ':19 'exec':53 'execut':34 'exist':68 'exit':62 'extern':127 'featur':85 'file':36 'fix':88 'focus':79 'foundat':137 'function':4,14,40 'getynansw':44 'heavi':126 'includ':41 'input':52 'interact':32,46 'interfac':50 'introduc':125 'javascript':142 'key':39 'librari':76 'lightweight':10 'line':49 'maintain':77,135 'make':107 'manag':38 'modern':102 'need':90 'new':84 'node':2,7 'node.js':18,117,140 'oper':29 'path':67 'pattern':114 'primari':97 'process':33 'project':130,141 'promis':24,106 'promise-bas':23 'provid':21,136 'readconsol':42 'releas':80,83 'respect':70 'run':56 'safe':55 'scope':95 'shell':57 'simpl':101 'specif':16,93 'streamlin':121 'suf':1,6 'suf-nod':5 'suit':111 'system':37 'task':123 'travers':65 'typic':82 'util':3,13,94,138 'version':73 'walk':60 'well':110 'well-suit':109 'without':124 'wrapper':26","created_at":"2026-04-20T01:57:48.284241+00:00","updated_at":"2026-04-20T01:57:48.284241+00:00","problems":[{"fix":"Ensure you are using `import { readConsole } from 'suf-node';` in an ES Module environment (`\"type\": \"module\"` in `package.json`), or adjust your bundler configuration if applicable.","cause":"This typically occurs when attempting to use CommonJS `require` syntax or incorrect named imports in an ES Module context, or vice-versa, causing the module resolution to fail.","error":"TypeError: (0, suf_node_1.readConsole) is not a function"},{"fix":"Wrap asynchronous calls in `try...catch` blocks when using `await`, or append a `.catch(error => console.error(error))` to your Promise chains.","cause":"An asynchronous `suf-node` function (e.g., `Exec`, `Walk`, `readConsole`) returned a Promise that rejected, but the rejection was not caught by a `.catch()` block or an `await` within a `try...catch` statement.","error":"UnhandledPromiseRejectionWarning: Unhandled promise rejection."},{"fix":"Inspect the error message from the `Exec` rejection to understand the specific command failure. Check the command's syntax, ensure necessary executables are in the system's PATH, and verify file/directory permissions if applicable.","cause":"The `Exec` function's underlying shell command exited with a non-zero status code, indicating an error during its execution (e.g., command not found, permission denied, syntax error in the command).","error":"Error: Command failed: <your_command_here>"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/TheRealSyler/suf-node","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/suf-node","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}