This topic describes how to install and configure the SDK for TypeScript and JavaScript.
This topic describes how to install and configure the SDK for TypeScript and JavaScript.
To use the Oracle Cloud Infrastructure SDK for TypeScript and JavaScript in your project, import any service from ./oci-typescript-sdk/index.ts. For example:
You can download the SDK for TypeScript and JavaScript as a zip archive from GitHub. It contains the SDK, all of its dependencies, documentation, and examples.
Installing with yum 🔗
If you're using Oracle Linux 7 or 8, you can use yum to install the OCI SDK for
TypeScript and JavaScript.
OS Management System needs to be enabled for the
compute instance. See the OS Management documentation for more
information.
Node version 14 or 16 needs to be added in the software source
list by OS Management. See the Software Source documentation for more
information on adding Nodejs 14 or 16 to the Software Source.
The
oci-typescript-sdk yum package will only work for Node version
14 or 16. The oci-sdk package will be installed into the
global node_modules folder. To use the oci-sdk
package in a project, link the oci-sdk global package to your local
project.
For
example:
# Assuming you are in your project's top level directory
npm link oci-sdk
# You should now see oci-sdk package in your local project's node_modules folder
Because the oci-sdk package is globally installed, you must update the
import statements for oci-sdk's sub-packages when running the
oci-typescript-sdk examples on GitHub. For example:
Copy
import * as identity from "oci-identity"; // Change needed
import * as oci from "oci-sdk"; // No change needed
import * as identity from "oci-sdk/node_modules/oci-identity"; //Changed
import * as oci from "oci-sdk"; // No change
Using the SDK for TypeScript and JavaScript with NPM 🔗
The default configuration location is "~/.oci/config" and "DEFAULT" profile is used. You can use ConfigFileAuthenticationDetailsProvider with or without specifying the configuration location and profile name:
Copy
// TypeScript
import common = require("oci-common");
// Using default configuration
const provider: common.ConfigFileAuthenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider();
// Using personal configuration
const configurationFilePath = "~/your_config_location";
const configProfile = "your_profile_name";
const provider: common.ConfigFileAuthenticationDetailsProvider = new common.ConfigFileAuthenticationDetailsProvider(
configurationFilePath,
configProfile
);
Copy
// JavaScript
const common = require("oci-common");
// Using default configurations
const provider = new common.ConfigFileAuthenticationDetailsProvider();
// Using personal configuration
const configurationFilePath = "~/your_config_location";
const configProfile = "your_profile_name";
const provider = new common.ConfigFileAuthenticationDetailsProvider(
configurationFilePath,
configProfile
);
Configuring Custom Options
In the configuration file, you can insert custom key-value pairs that you define, and then reference them as necessary. For example, you could specify a frequently used compartment ID in the config file: