「Node.js」モジュールを呼び出すサンプル

2020年11月23日

1.モジュールの作成sample.js

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
exports.outMsg = function(){
return "this is a sample data";
}
exports.outMsg = function(){ return "this is a sample data"; }
exports.outMsg = function(){

    return "this is a sample data";
}

2.モジュールの読み込みmain.js

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
var cft= require('./sample.js');
console.log( cft.outMsg() );
var cft= require('./sample.js'); console.log( cft.outMsg() );
var cft= require('./sample.js');
console.log( cft.outMsg() );

 

Node.js

Posted by arkgame