O'Reilly logo

JUNOS Automation Cookbook by Adam Chappell

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

The modification in steps 1 and 2 are slightly different between Node.js and Python due to the asynchronous nature of Node.js. But regardless, in both languages we use the stat system call to check for both, the existence and the file permissions on a well-known file, ~/.pwaccess, in the user's home directory. If the file doesn't exist, the stat call will throw an exception.

We use the synchronous version of the stat call in Node.js which results in the exception behavior, rather than an error parameter in a callback. It's generally not wise to mix synchronous and asynchronous code in Node.js, but using synchronous functions to set up execution before settling in a asynchronous mode for main runtime is a common pattern.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required