How to rotate Android simulator/device while running a test case using javascript

While running my node.js Selenium/Appium test cases on Saucelabs for older versions of Android I need to be able to rotate the device between horizontal and vertical throughout my test. I see that there are some Java Ruby and PHP ways to do this, but has anyone come up with a JS solution? Something that doesn’t require a library would be preferable…

It should be noted that driver.rotate(ScreenOrientation.LANDSCAPE) does not work because ScreenOrientation is not a function.