Ask coding questions

← Back to all posts
Exported Module Functions are not Working in Node.js
vedprad1 (892)

I was working on a program that involved my own module. While I was testing it, though, I realized that an exported function that I was working on had stopped working.

I created a new repl with a simplified module, and that yet still does not work. Can anyone see where the error is? I appreciate all the help!

The error: oof.hello is not a function

EDIT:

For some reason, the simplified repl has started working, but the program I am working on has not. I have posted it here.

Comments
hotnewtop
blazelon (0)

Assign the function you want to export from the file created by you to module.exports.
And in index.js, import the module by assigning a variable to require('./yourFileName')

malvoliothegood (796)

Line 7 is your problem module.exports = (d, t) => {
Have a look at this page. It shows how to create a node module and import functions that it contains: https://www.tutorialkart.com/nodejs/create-a-nodejs-module/

vedprad1 (892)

@malvoliothegood : I still do not see the problem. Isn't my code correct?

vedprad1 (892)

@malvoliothegood : Thanks for your help, but I still do not get the problem with the module.exports function. I have decided to turn that into a regular exported function instead, so there is no problem now.

Thanks for your help, though.