'TypeError: is not a function' in Node.js
up vote
24
down vote
favorite
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?
javascript node.js
add a comment |
up vote
24
down vote
favorite
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?
javascript node.js
3
@ckruczek: It's an ESL/cultural thing, it's not meant rudely, despite how it comes across in written English. I've replaced it with something more appropriate (er, I hope).
– T.J. Crowder
Nov 23 '15 at 6:59
add a comment |
up vote
24
down vote
favorite
up vote
24
down vote
favorite
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?
javascript node.js
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?
javascript node.js
javascript node.js
edited Nov 9 at 20:28
Hongarc
2,1401723
2,1401723
asked Nov 23 '15 at 6:42
Karthick Gk
125118
125118
3
@ckruczek: It's an ESL/cultural thing, it's not meant rudely, despite how it comes across in written English. I've replaced it with something more appropriate (er, I hope).
– T.J. Crowder
Nov 23 '15 at 6:59
add a comment |
3
@ckruczek: It's an ESL/cultural thing, it's not meant rudely, despite how it comes across in written English. I've replaced it with something more appropriate (er, I hope).
– T.J. Crowder
Nov 23 '15 at 6:59
3
3
@ckruczek: It's an ESL/cultural thing, it's not meant rudely, despite how it comes across in written English. I've replaced it with something more appropriate (er, I hope).
– T.J. Crowder
Nov 23 '15 at 6:59
@ckruczek: It's an ESL/cultural thing, it's not meant rudely, despite how it comes across in written English. I've replaced it with something more appropriate (er, I hope).
– T.J. Crowder
Nov 23 '15 at 6:59
add a comment |
3 Answers
3
active
oldest
votes
up vote
49
down vote
This happened to me many times 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
You saved me today :)
– arslan
Dec 21 '16 at 11:46
You saved me hours of banging my head to the wall. Thank you!
– mephisto123
Jan 13 at 12:42
indeed saver! not much said...directly to the point :)
– oetoni
Aug 13 at 16:50
add a comment |
up vote
28
down vote
With NodeJS modules, to make something public, you have to export it. Add this to the end of index.js
:
module.exports.AddNumbers = AddNumbers;
Here it is running on my machine:
$ cat index.js
function AddNumbers(a,b){
return a+b;
}
module.exports.AddNumbers = AddNumbers;
$ cat example.js
var index = require('./index');
var v2 = index.AddNumbers(5,6);
console.log(v2);
$ node example.js
11
I tried the above line still i'm getting the same error.
– Karthick Gk
Nov 23 '15 at 12:11
1
@KarthickGk: Then something else is wrong, the above works.
– T.J. Crowder
Nov 23 '15 at 12:32
Thanks a lot now its working fine.
– Karthick Gk
Nov 23 '15 at 13:28
add a comment |
up vote
2
down vote
If you need to expose a specific component, function or a variable to public. You have to exports
those components using JavaScript modules.
let add = (a,b)=>{
return ( a+b);
}
module.exports.add=add;
or if you want to expose multiple functions, you can do as follows.
let add = (a,b)=>{
return (a+b);
}
let subtract = (a, b)=>{
return (a-b);
}
module.exports={
add : add,
subtract : subtract
};
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
49
down vote
This happened to me many times 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
You saved me today :)
– arslan
Dec 21 '16 at 11:46
You saved me hours of banging my head to the wall. Thank you!
– mephisto123
Jan 13 at 12:42
indeed saver! not much said...directly to the point :)
– oetoni
Aug 13 at 16:50
add a comment |
up vote
49
down vote
This happened to me many times 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
You saved me today :)
– arslan
Dec 21 '16 at 11:46
You saved me hours of banging my head to the wall. Thank you!
– mephisto123
Jan 13 at 12:42
indeed saver! not much said...directly to the point :)
– oetoni
Aug 13 at 16:50
add a comment |
up vote
49
down vote
up vote
49
down vote
This happened to me many times 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
This happened to me many times 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 Jun 17 '16 at 16:43
shimi_tap
4,83941621
4,83941621
You saved me today :)
– arslan
Dec 21 '16 at 11:46
You saved me hours of banging my head to the wall. Thank you!
– mephisto123
Jan 13 at 12:42
indeed saver! not much said...directly to the point :)
– oetoni
Aug 13 at 16:50
add a comment |
You saved me today :)
– arslan
Dec 21 '16 at 11:46
You saved me hours of banging my head to the wall. Thank you!
– mephisto123
Jan 13 at 12:42
indeed saver! not much said...directly to the point :)
– oetoni
Aug 13 at 16:50
You saved me today :)
– arslan
Dec 21 '16 at 11:46
You saved me today :)
– arslan
Dec 21 '16 at 11:46
You saved me hours of banging my head to the wall. Thank you!
– mephisto123
Jan 13 at 12:42
You saved me hours of banging my head to the wall. Thank you!
– mephisto123
Jan 13 at 12:42
indeed saver! not much said...directly to the point :)
– oetoni
Aug 13 at 16:50
indeed saver! not much said...directly to the point :)
– oetoni
Aug 13 at 16:50
add a comment |
up vote
28
down vote
With NodeJS modules, to make something public, you have to export it. Add this to the end of index.js
:
module.exports.AddNumbers = AddNumbers;
Here it is running on my machine:
$ cat index.js
function AddNumbers(a,b){
return a+b;
}
module.exports.AddNumbers = AddNumbers;
$ cat example.js
var index = require('./index');
var v2 = index.AddNumbers(5,6);
console.log(v2);
$ node example.js
11
I tried the above line still i'm getting the same error.
– Karthick Gk
Nov 23 '15 at 12:11
1
@KarthickGk: Then something else is wrong, the above works.
– T.J. Crowder
Nov 23 '15 at 12:32
Thanks a lot now its working fine.
– Karthick Gk
Nov 23 '15 at 13:28
add a comment |
up vote
28
down vote
With NodeJS modules, to make something public, you have to export it. Add this to the end of index.js
:
module.exports.AddNumbers = AddNumbers;
Here it is running on my machine:
$ cat index.js
function AddNumbers(a,b){
return a+b;
}
module.exports.AddNumbers = AddNumbers;
$ cat example.js
var index = require('./index');
var v2 = index.AddNumbers(5,6);
console.log(v2);
$ node example.js
11
I tried the above line still i'm getting the same error.
– Karthick Gk
Nov 23 '15 at 12:11
1
@KarthickGk: Then something else is wrong, the above works.
– T.J. Crowder
Nov 23 '15 at 12:32
Thanks a lot now its working fine.
– Karthick Gk
Nov 23 '15 at 13:28
add a comment |
up vote
28
down vote
up vote
28
down vote
With NodeJS modules, to make something public, you have to export it. Add this to the end of index.js
:
module.exports.AddNumbers = AddNumbers;
Here it is running on my machine:
$ cat index.js
function AddNumbers(a,b){
return a+b;
}
module.exports.AddNumbers = AddNumbers;
$ cat example.js
var index = require('./index');
var v2 = index.AddNumbers(5,6);
console.log(v2);
$ node example.js
11
With NodeJS modules, to make something public, you have to export it. Add this to the end of index.js
:
module.exports.AddNumbers = AddNumbers;
Here it is running on my machine:
$ cat index.js
function AddNumbers(a,b){
return a+b;
}
module.exports.AddNumbers = AddNumbers;
$ cat example.js
var index = require('./index');
var v2 = index.AddNumbers(5,6);
console.log(v2);
$ node example.js
11
edited Nov 23 '15 at 12:38
answered Nov 23 '15 at 6:46
T.J. Crowder
669k11611841279
669k11611841279
I tried the above line still i'm getting the same error.
– Karthick Gk
Nov 23 '15 at 12:11
1
@KarthickGk: Then something else is wrong, the above works.
– T.J. Crowder
Nov 23 '15 at 12:32
Thanks a lot now its working fine.
– Karthick Gk
Nov 23 '15 at 13:28
add a comment |
I tried the above line still i'm getting the same error.
– Karthick Gk
Nov 23 '15 at 12:11
1
@KarthickGk: Then something else is wrong, the above works.
– T.J. Crowder
Nov 23 '15 at 12:32
Thanks a lot now its working fine.
– Karthick Gk
Nov 23 '15 at 13:28
I tried the above line still i'm getting the same error.
– Karthick Gk
Nov 23 '15 at 12:11
I tried the above line still i'm getting the same error.
– Karthick Gk
Nov 23 '15 at 12:11
1
1
@KarthickGk: Then something else is wrong, the above works.
– T.J. Crowder
Nov 23 '15 at 12:32
@KarthickGk: Then something else is wrong, the above works.
– T.J. Crowder
Nov 23 '15 at 12:32
Thanks a lot now its working fine.
– Karthick Gk
Nov 23 '15 at 13:28
Thanks a lot now its working fine.
– Karthick Gk
Nov 23 '15 at 13:28
add a comment |
up vote
2
down vote
If you need to expose a specific component, function or a variable to public. You have to exports
those components using JavaScript modules.
let add = (a,b)=>{
return ( a+b);
}
module.exports.add=add;
or if you want to expose multiple functions, you can do as follows.
let add = (a,b)=>{
return (a+b);
}
let subtract = (a, b)=>{
return (a-b);
}
module.exports={
add : add,
subtract : subtract
};
add a comment |
up vote
2
down vote
If you need to expose a specific component, function or a variable to public. You have to exports
those components using JavaScript modules.
let add = (a,b)=>{
return ( a+b);
}
module.exports.add=add;
or if you want to expose multiple functions, you can do as follows.
let add = (a,b)=>{
return (a+b);
}
let subtract = (a, b)=>{
return (a-b);
}
module.exports={
add : add,
subtract : subtract
};
add a comment |
up vote
2
down vote
up vote
2
down vote
If you need to expose a specific component, function or a variable to public. You have to exports
those components using JavaScript modules.
let add = (a,b)=>{
return ( a+b);
}
module.exports.add=add;
or if you want to expose multiple functions, you can do as follows.
let add = (a,b)=>{
return (a+b);
}
let subtract = (a, b)=>{
return (a-b);
}
module.exports={
add : add,
subtract : subtract
};
If you need to expose a specific component, function or a variable to public. You have to exports
those components using JavaScript modules.
let add = (a,b)=>{
return ( a+b);
}
module.exports.add=add;
or if you want to expose multiple functions, you can do as follows.
let add = (a,b)=>{
return (a+b);
}
let subtract = (a, b)=>{
return (a-b);
}
module.exports={
add : add,
subtract : subtract
};
answered Nov 11 at 6:38
Aravinda Meewalaarachchi
509311
509311
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f33865068%2ftypeerror-is-not-a-function-in-node-js%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
@ckruczek: It's an ESL/cultural thing, it's not meant rudely, despite how it comes across in written English. I've replaced it with something more appropriate (er, I hope).
– T.J. Crowder
Nov 23 '15 at 6:59