Skip to main content
Glama
test-npm-config.jsβ€’2.61 kB
#!/usr/bin/env node /** * Test NPM configuration and authentication */ import { execSync } from "child_process"; import { readFileSync } from "fs"; console.log("πŸ” Testing NPM Configuration...\n"); // Check if .npmrc exists try { const npmrc = readFileSync(".npmrc", "utf8"); console.log("βœ… .npmrc file exists"); console.log("πŸ“ Contents:"); console.log( npmrc .split("\n") .map((line) => " " + line) .join("\n"), ); } catch (error) { console.log("❌ .npmrc file not found"); process.exit(1); } // Check NPM_TOKEN environment variable console.log("\nπŸ”‘ Environment Variable Check:"); if (process.env.NPM_TOKEN) { console.log("βœ… NPM_TOKEN is set"); console.log(`πŸ“ Token length: ${process.env.NPM_TOKEN.length} characters`); } else { console.log("⚠️ NPM_TOKEN environment variable not set"); console.log('πŸ’‘ Set it with: export NPM_TOKEN="your_token_here"'); } // Test npm whoami (only if token is set) console.log("\nπŸ‘€ Authentication Test:"); if (process.env.NPM_TOKEN) { try { const whoami = execSync("npm whoami", { encoding: "utf8" }).trim(); console.log(`βœ… Authenticated as: ${whoami}`); } catch (error) { console.log("❌ Authentication failed"); console.log("πŸ’‘ Make sure your NPM_TOKEN is valid"); } } else { console.log("⏭️ Skipping authentication test (no token set)"); } // Test publish dry run console.log("\nπŸ“¦ Package Test:"); try { const dryRun = execSync("npm publish --dry-run", { encoding: "utf8" }); console.log("βœ… Package is ready for publishing"); // Extract package size info const sizeMatch = dryRun.match(/package size:\s*([^\n]+)/i); const filesMatch = dryRun.match(/([0-9]+) files/); if (sizeMatch) console.log(`πŸ“ Package size: ${sizeMatch[1]}`); if (filesMatch) console.log(`πŸ“ File count: ${filesMatch[1]} files`); } catch (error) { console.log("❌ Package test failed"); if (error.message.includes("ENEEDAUTH")) { console.log("πŸ” Authentication required for publishing"); } else { console.log("πŸ” Error:", error.message.split("\n")[0]); } } console.log("\nπŸ“‹ Summary:"); console.log(" βœ… .npmrc configured with environment variable"); console.log(" πŸ”’ Token safely stored in environment (not in file)"); console.log(" πŸ“¦ Package configuration validated"); console.log(" πŸš€ Ready for publishing when authenticated"); console.log("\nπŸ’‘ Next steps:"); console.log(' 1. Set NPM_TOKEN: export NPM_TOKEN="your_token_here"'); console.log(" 2. Verify auth: npm whoami"); console.log(" 3. Publish: npm publish");

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/docdyhr/mcp-wordpress'

If you have feedback or need assistance with the MCP directory API, please join our Discord server