How to call the function from other node js file

VG__ picture VG__ · Feb 17, 2016 · Viewed 31.3k times · Source

These codes are stored in separate file and I tried to call the get method from this file to another nodejs, but I am getting only [Function] as a out put.

Can any one tell me how to call the get method from this file to another node js file

'use strict';
var createAPIRequest = require('../../lib/apirequest');
function Fitness(options) {
  var self = this;
  this._options = options || {};
  this.users = {
    dataSources: {
      get: function(params, callback) {
        var parameters = {
          options: {
            url: 'https://www.googleapis.com/fitness/v1/users/{userId}/dataSources/{dataSourceId}',
            method: 'GET'
          },
          params: params,
          requiredParams: ['userId', 'dataSourceId'],
          pathParams: ['dataSourceId', 'userId'],
          context: self
        };
        return createAPIRequest(parameters, callback);
      }     }   }; }

Answer

akc42 picture akc42 · Feb 17, 2016

In this file you add

module.exports = Fitness

Then where you want to use it you do

var Fitness = require('./fitness');