{"library":"netrc-parser","title":"Netrc File Parser for Node.js","description":"netrc-parser is a Node.js library designed to parse, load, and save `.netrc` files, which are traditionally used by FTP clients and other utilities to store login credentials for remote machines. The package provides both synchronous and asynchronous APIs for file operations and machine access. Currently at version 3.1.6, the library appears to be in a maintenance phase with its last significant update several years ago (circa 2019), indicating a stable API. It ships with TypeScript type definitions, making it suitable for modern TypeScript projects, and differentiates itself by offering a straightforward interface for managing machine entries programmatically. While there are other `netrc` parsing solutions available, this package focuses specifically on the Node.js ecosystem, handling common patterns like `login`, `password`, and `account` fields.","language":"javascript","status":"maintenance","last_verified":"Sun Apr 19","install":{"commands":["npm install netrc-parser"],"cli":null},"imports":["import Netrc from 'netrc-parser';","import { default as Netrc } from 'netrc-parser';","const Netrc = require('netrc-parser').default;","import type Netrc from 'netrc-parser';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import Netrc from 'netrc-parser';\n\nasync function manageNetrcCredentials() {\n  const netrc = new Netrc();\n  try {\n    // Load the .netrc file from the user's home directory\n    await netrc.load();\n    console.log('Netrc file loaded successfully.');\n\n    // Access credentials for a specific machine\n    const githubMachine = netrc.machines['github.com'];\n    if (githubMachine) {\n      console.log(`GitHub Login: ${githubMachine.login}`);\n      console.log(`GitHub Password: ${githubMachine.password ? '[REDACTED]' : 'N/A'}`);\n    } else {\n      console.log('No entry found for github.com. Adding one...');\n      netrc.machines['github.com'] = {\n        login: 'mygithubuser',\n        password: process.env.GITHUB_TOKEN ?? 'my-secret-token',\n        account: 'mygithubaccount'\n      };\n      console.log('Added a placeholder entry for github.com.');\n    }\n\n    // Save any changes back to the .netrc file\n    await netrc.save();\n    console.log('Netrc file saved with potential updates.');\n\n  } catch (error) {\n    if (error instanceof Error) {\n      console.error(`Failed to process netrc: ${error.message}`);\n      if (error.message.includes('permission')) {\n        console.error('Check file permissions (e.g., chmod 600 ~/.netrc).');\n      }\n    } else {\n      console.error('An unexpected error occurred.');\n    }\n  }\n}\n\nmanageNetrcCredentials();","lang":"typescript","description":"Demonstrates loading, accessing, modifying, and saving `.netrc` entries, including basic error handling for file operations.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}