how to implement nodejs include as for example in php? so that another js file is connected to one js file
Closed due to the fact that off-topic participants Edward , 0xdb , Air , dlarchikov , C.Raf.T 20 May '18 at 17:38 .
It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:
- " Learning tasks are allowed as questions only on the condition that you tried to solve them yourself before asking a question . Please edit the question and indicate what caused you difficulties in solving the problem. For example, give the code you wrote, trying to solve the problem "- Edward, 0xdb, dlarchikov
- This is after all in any example on node.js there is - Vyacheslav Gusser
- what is???? how to add one written .js to another as in php function include ????? there is no such thing - shol
- not so read the question and start to comment, there is, no, in any textbook .... - shol
- If you expect to get the behavior exactly the same as in php, as it includes the include script in the context of the script in which the include is done, and all the global variables in the file that include'li are available in the calling script, then no, that does not work in node. LEARN DOCUMENTATION, you did not read the documentation and start asking questions - Vyacheslav Gusser
- so I asked, maybe there are thoughts how to implement - shol
|
2 answers
require ()
var fs = require("fs"); - to use functions, variables, etc. you need to export them (these are the basics of node.js) - Alexandr Maliovaniy
- read carefully my question - shol
- I did not mean the import of modules - shol
|
To include scripts into each other is used
const sum = require('./sum'); And inside sum.js, this export
module.exports = (a, b) => a + b Here is the documentation for the https://nodejs.org/api/modules.html modules
|