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, 2020 in Node-js by kartik
• 37,520 points
17,289 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.

Hope it helps!!

To know more about it, enroll in Node.js training today.

Thank You!!

answered Oct 15, 2020 by Niroj
• 82,840 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, 2020 by anonymous
• 140 points

Related Questions In Node-js

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, 2020 in Node-js by Niroj
• 82,840 points
873 views
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, 2020 in Node-js by Niroj
• 82,840 points
10,431 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, 2020 in Node-js by Niroj
• 82,840 points
877 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, 2020 in Node-js by Niroj
• 82,840 points
7,217 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, 2020 in Node-js by Niroj
• 82,840 points
910 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, 2020 in Node-js by Niroj
• 82,840 points
9,805 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, 2020 in Node-js by Niroj
• 82,840 points
1,492 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, 2020 in Node-js by Niroj
• 82,840 points
23,959 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, 2020 in Node-js by Niroj
• 82,840 points
2,285 views
0 votes
1 answer

Error:Failed to parse json-This is not a bug in npm.

Hello @kartik, Try this: npm cache clean Hope it works!! Thank ...READ MORE

answered Nov 27, 2020 in Node-js by Niroj
• 82,840 points
4,747 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP