1
例如,我有profile.js什么要求()返回实际的文件或功能
var EventEmitter = require("events").EventEmitter;
var https = require("https");
var http = require("http");
var util = require("util");
function Profile(username) {
// function code here
}
util.inherits(Profile, EventEmitter);
module.exports = Profile;
在我app.js,我有
var Profile = require("./profile.js");
var studentProfile = new Profile("chalkers");
/**
* When the JSON body is fully recieved the
* the "end" event is triggered and the full body
* is given to the handler or callback
**/
studentProfile.on("end", console.dir);
/**
* If a parsing, network or HTTP error occurs an
* error object is passed in to the handler or callback
**/
studentProfile.on("error", console.error);
所以变量profile.js本身还是函数Profile(用户名)?如果profile.js具有不同的功能,例如我在profile.js中具有函数SetProfile(username),那么应该如何导出这两个函数并在app.js中使用它们?
如果profile.js具有不同的功能,比如我在profile.js中有函数SetProfile(username),那么应该如何导出这两个函数并在app.js中使用它们? –
'module.exports.x = function x(){}; module.exports.y = function y(){};' – Amit
我可以将它们导入到app.js的一个地方吗?像var Functions = require('./ profile.js'),然后使用Functions.x(),Function.y() –