We know that each module corresponds to a js file. This article writes the simplest module hello.js, and then requires the customized module in another js file (main.js).
hello.js
function hello( name) {
console.log('hello, ' name);
}
exports.hello = hello;
main.js
var h = require('./hello');
h. hello('snandy');
Convention: hello.js and main.js are in the same directory, such as the node directory
Open the command line, enter the node directory, and execute the command
node main.js
You can see the command line output: hello, snandy
Note:
The require parameter in main.js cannot be "hello" and must be preceded by "./".
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn