Add an npm module to a script

npm modules are packages or libraries that are published on the npm registry and can be easily installed. npm is the default package manager for Node.js and provides a vast ecosystem of open-source modules that developers can leverage to add functionality to their projects.

There are two types of npm modules in Neptune DXP - Open Edition, accessible through the NPM Modules tool in the Cockpit:

Internal

These are default npm modules that Neptune DXP - Open Edition provides that it considers essential for server-side scripting

Custom

Any npm module installed through the npm modules npm Modules that Neptune - DXP Open Edition provides

Prerequisites

  • You have created a new script.

  • The script is in edit mode. An open lock icon for the script in the Application component pane indicates that you have opened the script and can edit it. If the script is in display mode, right-click the script and select Edit.

Procedure

  1. Drag and drop a module, for example, axios, from the Reusable components pane into the script in the Application components pane.

  2. Call the module within the script, for example:

    // Axios, a popular JavaScript library used for making HTTP requests from a web browser or Node.js
    const axios = modules.axios;
The Internal and Custom code snippets categories (accessed by right-clicking a code line in the Script editing pane and selecting Code Snippets) provide default call functions to fill for a script to call the particular module and are available in the Code Snippets dialog by default.

Results

  • You have added an npm module to a script.