{"id":13597,"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.","status":"maintenance","version":"3.1.6","language":"javascript","source_language":"en","source_url":"https://github.com/jdxcode/node-netrc-parser","tags":["javascript","netrc","typescript"],"install":[{"cmd":"npm install netrc-parser","lang":"bash","label":"npm"},{"cmd":"yarn add netrc-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add netrc-parser","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primary ESM/TypeScript import for the default export.","symbol":"Netrc","correct":"import Netrc from 'netrc-parser';"},{"note":"Alternative ESM/TypeScript import for default export. Using `import { Netrc } from ...` will fail as it's not a named export.","wrong":"import { Netrc } from 'netrc-parser';","symbol":"Netrc","correct":"import { default as Netrc } from 'netrc-parser';"},{"note":"CommonJS import; the package exports its main class as the default export, hence requiring `.default`.","wrong":"const Netrc = require('netrc-parser');","symbol":"Netrc","correct":"const Netrc = require('netrc-parser').default;"},{"note":"TypeScript type-only import for the default export. Direct named type import will fail.","wrong":"import { Netrc } from 'netrc-parser';","symbol":"Netrc","correct":"import type Netrc from 'netrc-parser';"}],"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."},"warnings":[{"fix":"Always ensure your `~/.netrc` file has strict permissions, typically `chmod 600 ~/.netrc` on Unix-like systems, making it readable and writable only by the file owner.","message":"The `.netrc` file is highly sensitive and typically stores plaintext credentials. Improper file permissions (e.g., readable by other users) can lead to security vulnerabilities. Many tools, including the standard Unix `ftp` utility and Python's `netrc` module, will refuse to parse or load `.netrc` files with insecure permissions (e.g., `NetrcParseError` on POSIX systems if not `chmod 600`). This package may not enforce these checks by default, requiring manual permission management by the user.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For CommonJS, use `const Netrc = require('netrc-parser').default;`. For ESM/TypeScript, use `import Netrc from 'netrc-parser';`.","message":"This package exports its primary `Netrc` class as a default export. In CommonJS environments, this means you must access it via `.default` after requiring the package (e.g., `require('netrc-parser').default`). Directly requiring `require('netrc-parser')` will return an object containing the default export, not the class itself, leading to instantiation errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Adhere strictly to the `.netrc` file format: `machine HOST login USER password PASSWORD account ACCOUNT`. Ensure comments start with `#` at the beginning of a line. Test with a minimal `.netrc` file if encountering parsing issues.","message":"Like many `netrc` parsers, `netrc-parser` can be strict about the `.netrc` file format. Non-standard entries, unknown tokens, or incorrectly formatted lines (e.g., comments not starting a line, unexpected whitespace) can lead to parsing errors or unexpected behavior. Some `netrc` implementations may tolerate more relaxed formats, which might cause compatibility issues if files are shared between different tools.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'2019':74 '3.1.6':55 'access':51 'account':128 'ago':72 'api':45,78 'appear':58 'asynchron':44 'avail':112 'circa':73 'client':27 'common':122 'credenti':34 'current':52 'definit':84 'design':13 'differenti':93 'ecosystem':120 'entri':103 'field':129 'file':2,20,47 'focus':115 'ftp':26 'handl':121 'indic':75 'interfac':99 'javascript':130 'last':67 'librari':12,57 'like':124 'load':16 'login':33,125 'machin':37,50,102 'mainten':63 'make':85 'manag':101 'modern':89 'netrc':1,7,19,109,131 'netrc-pars':6 'node.js':5,11,119 'offer':96 'oper':48 'packag':39,114 'pars':15,110 'parser':3,8 'password':126 'pattern':123 'phase':64 'programmat':104 'project':91 'provid':40 'remot':36 'save':18 'sever':70 'ship':80 'signific':68 'solut':111 'specif':116 'stabl':77 'store':32 'straightforward':98 'suitabl':87 'synchron':42 'tradit':23 'type':83 'typescript':82,90,132 'updat':69 'use':24 'util':30 'version':54 'year':71","created_at":"2026-04-20T01:55:19.600970+00:00","updated_at":"2026-04-20T01:55:19.600970+00:00","problems":[{"fix":"For CommonJS: `const Netrc = require('netrc-parser').default;`. For ESM/TypeScript: `import Netrc from 'netrc-parser';` or `import { default as Netrc } from 'netrc-parser';`.","cause":"Attempting to instantiate `Netrc` in CommonJS without accessing the `.default` export, or in ESM/TypeScript with an incorrect named import.","error":"TypeError: Netrc is not a constructor"},{"fix":"Adjust the file permissions for `~/.netrc` to be readable and writable only by the owner: `chmod 600 ~/.netrc`. Also, ensure the parent directory has appropriate permissions.","cause":"The current user does not have sufficient read/write permissions for the `.netrc` file or the directory containing it. This is a common security measure.","error":"Error: EACCES: permission denied, open '/home/user/.netrc'"},{"fix":"Inspect your `~/.netrc` file for syntax errors. Ensure each `machine` block is correctly formatted with `login`, `password`, and `account` (if present) on separate lines or correctly space-separated, and that no unexpected characters or incomplete entries exist.","cause":"The `.netrc` file contains a malformed entry or an unexpected token, causing the parser to fail. This could be due to extra data on a `machine` line or a missing value.","error":"SyntaxError: Unexpected token 'login'"}],"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/jdxcode/node-netrc-parser","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/netrc-parser","openapi_spec":null,"status_page":null,"smithery":null,"categories":["auth-security","serialization"],"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}}