How to build an NPM Private Repo in Apigee Edge to serve your packages

0 0 822

How to build an NPM Private Repo to serve your packages

The following article is based on the content from npm-private-repo-apigee-proxy Github Repo.

This API provides a basic scaffolding code to host NPM private packages. The use case for this solution is when an organization wants to leverage Node.js and NPM to load packages from repos that aren't exposed publicly. Check the following tutorial for possible alternatives to hosting NPM private modules npm-private-modules.

How it works

NPM Private Repo Apigee Proxy can be deployed on any Apigee Edge organization. Essentially, it's a file server protected with Basic Authentication, see app.js to configure it. For instance: the file npm-package1-1.0.0.tgz can be fetched with this URL https://npmrepouser:passw0rd@testmyapi-test.apigee.net/npm-private-repo-proxy/npm-package1-1.0.0.tgz.

So, modules can be installed from anywhere by providing the URL. In our case, npm-package1-1.0.0.tgz can be installed using this command:

$ npm install "https://npmrepouser:passw0rd@testmyapi-test.apigee.net/npm-private-repo-proxy/npm-package1-1.0.0.tgz" --save

The package installed under node_modules is a simple function that prints out a string:

    var local_package = require('npm-package1');

    //This will execute the module stored locally
    local_package.sayHello();
    //prints "Look Ma! Hello World from local module!"

Deploy it in your own Org

There are a few way to deploy this API proxy. The easier one is to manually importing it through the UI npm-private-repo-proxy.zip stored under the target folder.

The second option is to leverage Apigee Deploy Grunt Plugin.

Version history
Last update:
‎03-29-2015 02:05 PM
Updated by: