1# Environment 2 3This module provides JS APIs for obtaining the root directories of the storage and public files. 4 5> **NOTE** 6> 7> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. 8> - The APIs of this module are system APIs and cannot be called by third-party applications. 9 10## Modules to Import 11 12```js 13import environment from '@ohos.environment'; 14``` 15 16## environment.getStorageDataDir 17 18getStorageDataDir():Promise<string> 19 20Obtains the root directory of the storage. This API uses a promise to return the result. 21 22**System capability**: SystemCapability.FileManagement.File.Environment 23 24- Return value 25 26 | Type | Description | 27 | --------------------- | ---------------- | 28 | Promise<string> | Promise returned with the root directory of the storage.| 29 30- Example 31 32 ```js 33 environment.getStorageDataDir().then(function(path){ 34 console.info("getStorageDataDir successfully:"+ path); 35 }).catch(function(error){ 36 console.info("getStorageDataDir failed with error:"+ error); 37 }); 38 ``` 39 40## environment.getStorageDataDir 41 42getStorageDataDir(callback:AsyncCallback<string>):void 43 44Obtains the root directory of the storage. This API uses an asynchronous callback to return the result. 45 46**System capability**: SystemCapability.FileManagement.File.Environment 47 48- Parameters 49 50 | Name | Type | Mandatory| Description | 51 | -------- | --------------------------- | ---- | -------------------------------- | 52 | callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the root directory of the storage.| 53 54- Example 55 56 ```js 57 environment.getStorageDataDir(function(error, path){ 58 // do something 59 }); 60 ``` 61 62## environment.getUserDataDir 63 64getUserDataDir():Promise<string> 65 66Obtains the root directory of public files. This API uses a promise to return the result. 67 68**System capability**: SystemCapability.FileManagement.File.Environment 69 70- Return value 71 72 | Type | Description | 73 | --------------------- | ------------------ | 74 | Promise<string> | Promise returned with the root directory of public files.| 75 76- Example 77 78 ```js 79 environment.getUserDataDir().then(function(path){ 80 console.info("getUserDataDir successfully:"+ path); 81 }).catch(function(error){ 82 console.info("getUserDataDir failed with error:"+ error); 83 }); 84 ``` 85 86## environment.getUserDataDir 87 88getUserDataDir(callback:AsyncCallback<string>): void 89 90Obtains the root directory of public files. This API uses an asynchronous callback to return the result. 91 92**System capability**: SystemCapability.FileManagement.File.Environment 93 94- Parameters 95 96 | Name | Type | Mandatory| Description | 97 | -------- | --------------------------- | ---- | -------------------------------- | 98 | callback | AsyncCallback<string> | Yes | Asynchronous callback used to return the root directory of public files.| 99 100- Example 101 102 ```js 103 environment.getUserDataDir(function(error, path){ 104 // do something 105 }); 106 ``` 107