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,414 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

Why does "window is not defined" error occur in Next.js?

The "window is not defined" error in ...READ MORE

answered Dec 17, 2024 in Node-js by Navya
71 views
0 votes
0 answers

What is the main difference between REST APIs and GraphQL in a Node.js application?

With the help of code, can you ...READ MORE

Dec 17, 2024 in Node-js by Ashutosh
• 12,620 points
41 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, 2020 in Node-js by Niroj
• 82,840 points
916 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,565 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
957 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
10,005 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,574 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
24,054 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,332 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,880 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