IO模块交互学习
exports 声明一个模块 例如:
exports.shangke = function(){}
还可以这样
exports.shangke = function(str){
console.log('您输入的是:'+str);
}
function hello(){
console.log('this is hello');
}
exports.h = hello;
require 调用模块
var sk = require('./a.js');
demo:
var readline = require('readline');
var rl = readline.createInterface(process.stdin,process.stdout);
var sk = require('a.js');
rl.setPrompt('请输入:');
rl.prompt();
rl.on('line',(line) => {
var str = line.trim();
if(str == '0'){
console.log('欢迎你下次再来');
process.exit();
}else {
sk.shangke(str);
sk.h();
rl.prompt();
}
});
linux命令
tar zcvf ybb.gz nodejs //压缩文件
tar zxvf ybb//解压文件
npm install request//node模块安装
网友评论