1Password on Mastodon

Local NodeJS script - use item from 1password personal vault

vineet1passwdvineet1passwd Junior Member
Community Member

How can I use an item stored in 1Password personal vault from NodeJS script running locally? I see connect-sdk-js requires "1Password Connect API hosted on your infrastructure". Is it possible to do - op item get "Itemname" from NodeJS?

1Password Version: 8.10
Extension Version: Not Provided
OS Version: macOS 13.2 Ventura
Browser:_ Not Provided


  • Jack.P_1PJack.P_1P

    Team Member

    Hi @vineet1passwd:

    Great question! If you're looking to run your Node.js program locally, what may work best for you is the run command in 1Password CLI.

    run | 1Password CLI

    Using this, it would be possible to set an environment variable (either in your shell, or using the .env file) to a secret reference, like: op://vault/item/field. Next, use 1Password CLI to run the command: op run -- node main.js. 1Password CLI will process the environment variables and replace the secret reference in the environment variable with the value of the secret. At that point, you can use standard Node.js functions to get the value of the environment variable, which now contains the environment variable.

    Let me know if that helps, or if you'd like me to dig in a bit further with you!


  • vineet1passwdvineet1passwd Junior Member
    Community Member

    Thanks @Jack.P_1P. I was able to create .env file with entries like USERNAME=op://<VaultName>/<ItemId>/username. I then referenced the environment variable from nodejs script.js const userId = process.env.USERNAME;. I was then able to run the nodejs script by specifying in package.json -

    "scripts": {
        "scriptname": "op run --no-masking --env-file=\"./.env\" -- node ./script.js"
  • Jack.P_1PJack.P_1P

    Team Member

    Hi @vineet1passwd:

    Glad I could help! Let me know if there's anything else I can help you with.


Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file