Search code examples
node.jsrequirejsnpm

How to bundle node.js library into my application?


For example,nock library,it is used as

var nock = require('nock');

I want to pack the whole library as a single JS file and distribute as part of my application that only require a basic node.js runtime.

From the lib folder, I see files:

common.js  delayed_body.js  intercept.js  match_body.js  mixin.js  recorder.js  request_overrider.js  scope.js

How to concat them and use as part of my program?


Solution

  • You could use Browserify to bundle it and all it's dependencies.

    browserify node_modules/nock/index.js -o bundle.js
    

    Then you'll have a single file, bundle.js