Error:'TypeError: is not a function' in Node.js

0 votes

I'm getting the error while running the following code in Node.js

var assert = require('assert');
var request = require('request');
var index = require('./index');
it('verify javascript function', function(done) {
    var v2 = index.AddNumbers(5, 6);
    assert.equal(11, v2);
    done();
});

The index.js file contain the following code:

function AddNumbers(a,b){
    return a+b;
}

What am I doing wrong?

Oct 15 in Node-js by kartik
• 35,720 points
520 views

2 answers to this question.

0 votes

Hello @kartik,

Because of circular dependency, check if you have 2 classes that are requiring each other, remove one of them from requiring the other and the issue should be solved.

answered Oct 15 by Niroj
• 77,920 points
0 votes

You are exporting

module.exports.redir = redir;

That means that your import

const redir = require('./index');

is the exported object. redir happens to be one of its keys. To use the function, use

const redir = require('./index').redir;

or destructure directly into redir

const { redir } = require('./index');
answered Oct 21 by anonymous
• 140 points

Related Questions In Node-js

0 votes
1 answer

ReferenceError: primordials is not defined in node

Hello @kartik, Use following commands and install node v11.15.0: npm ...READ MORE

answered Jul 12 in Node-js by Niroj
• 77,920 points
2,413 views
0 votes
1 answer

How do you log content of a JSON object in Node.js?

Hello @kartik, Try this one: console.log("Session: %j", session); If the ...READ MORE

answered Jul 16 in Node-js by Niroj
• 77,920 points
51 views
0 votes
1 answer

How to host a Node.Js application in shared hosting?

Hello @kartik, You can run node.js server on a typical ...READ MORE

answered Jul 17 in Node-js by Niroj
• 77,920 points
1,111 views
0 votes
1 answer

How is an HTTP POST request made in node.js?

Hello @kartik, A easier way if you use ...READ MORE

answered Jul 20 in Node-js by Niroj
• 77,920 points
67 views
0 votes
1 answer

How to write files in Node.js?

Hello @kartik, Currently there are three ways to ...READ MORE

answered Jul 8 in Node-js by Niroj
• 77,920 points
97 views
0 votes
1 answer

How to Install a local module using npm?

Hello @kartik, This is what worked for me: npm ...READ MORE

answered Jul 9 in Node-js by Niroj
• 77,920 points
103 views
0 votes
1 answer

How to run Gulp tasks sequentially one after the other?

Hello @kartik, By default, gulp runs tasks simultaneously, ...READ MORE

answered Jul 12 in Node-js by Niroj
• 77,920 points
65 views
0 votes
1 answer

How to set environment variables from within package.json?

Hello @kartik, Set the environment variable in the ...READ MORE

answered Jul 13 in Node-js by Niroj
• 77,920 points
2,803 views
0 votes
1 answer

Error:TypeError: Object.values is not a function.

Hello @kartik, Object.values is a new feature . It is ...READ MORE

answered Oct 15 in Node-js by Niroj
• 77,920 points
49 views
0 votes
1 answer

How to print a stack trace in Node.js?

Hello @kartik, To print stacktrace of Error in console in ...READ MORE

answered Jul 9 in Node-js by Niroj
• 77,920 points
65 views