PhantomJS FileSystem API
The FileSystem module of PhantomJS provides mechanisms to manipulate files, folders, paths, and contents. It is also capable of handling file object streams. The API is handy and very easy to use.
Let us start with a very simple example, using the API to display the folder we are working on.
var fs = require('fs'); console.log("Working Directory: " + fs.workingDirectory); phantom.exit(0);
In the first line, we reference an instance of the FileSystem module using the require
keyword and passing fs
as the module name. With this, we can now access all the file and folder functions.