Use third-party libraries in applications in the ServiceNow IDE
Call third-party libraries in your application to use existing open-source functionality with the ServiceNow IDE.
Before you begin
Create a JavaScript module. For more information, see Create and use JavaScript modules in applications in the ServiceNow IDE.
To install and use packages from private registries, you must configure your Package Manager user settings in the ServiceNow IDE. For more information, see Install an npm package from a private registry with the ServiceNow IDE.
Role required: admin
About this task
Third-party libraries are added to applications as JavaScript modules. For general information about the syntax used to create JavaScript modules, see the JavaScript modules page on the MDN Web Docs website.
Important: You can't use third-party libraries that rely on unsupported functionality, such as unsupported APIs or ECMAScript features. For more information about unsupported functionality, see Third-party library support in Australia and JavaScript modules and third-party libraries.
Procedure
Navigate to All > App Development > ServiceNow IDE.
Open a workspace with an application.
From the Activity Bar, select the File Explorer view (
File Explorer\).
Open the
package.jsonfile for the application.Add the
dependenciesfield with the package name and version of any third-party libraries to use."dependencies": { "<package name>": "<version>" }Install the third-party library packages.
Use one of the following keyboard shortcuts to open the command palette:
- Windows: Ctrl-Shift-P
- Mac: Cmd-Shift-P
- Enter
Package Manager: Install Dependenciesand press Enter.
- Enter
Packages are installed in the
node_modulesdirectory.In a JavaScript module, import the library using an import statement.
In this example, the module includes a namespace import for the lodash module.
import * as lodash from "lodash"In this example, the module includes a named import for the camelCase function in the lodash module.
import camelCase from 'lodash'Call code imported from the library in your module to reuse it.
From the Status Bar, select Build and Install.
Build and Install
The active file that's open in the editor determines which application to build. If no files are open, select the application to build when prompted.
After building, the modules are added to the EcmaScript Module \[sys\_module\] table.
- Install an npm package from a private registry with the ServiceNow IDE
Install Node Package Manager (npm) packages from a private registry as dependencies in your application to use them as third-party libraries.
Parent Topic:Developing applications with the ServiceNow IDE
Related topics