Call function from different file? Also, creating new file does not have any language on it


#1

Hello,
Basically I created a package that will evaluate and display the result of a function called main. In the package, I have put in the message content line “eval main(x=2)” so basically in another file a function titled main will have its output displayed when x=2. The only issue is that the package cannot search other files for the function. In the package itself I can define a function main with

main = (x) ->
  x+47

Basically, in another file I want for the function called main to be evaluated and its result printed. Each file will have a different function itself but the function will be called main, whether it is x+5090 or x+1. Also, whenever I create a new file (not package) it is called untitled and has no programming language on it. No matter what I put, it is plain text and nothing else in coffescript or js.


#2

For your second question, I created a new FAQ:

Please keep topics separate in the future. This really should be two separate posts. I realize it is perhaps less convenient, but it helps others find what they’re looking for in the long run.

For your first question, you’re looking for the Node.js require function. You can require files at any time, even within the body of another function.


#3

Closing this topic since you say that your newest topic supersedes this one:


#4