# content.js function cont(cont){ console.log(“cont”+cont); };
module.exports=cont;
1 2
# 输出结果 contnihao
示例2
1 2 3 4
# index.js var content=require("./content");
content("nihao");
1 2 3 4 5 6 7 8 9 10 11
# content.js function cont(cont){ console.log("cont"+cont); };
function ent(ent){ console.log("ent"+ent); };
module.exports=cont; module.exports=ent;
1 2
#输出结果 entnihao
示例3
1 2 3 4 5
# index.js var content=require("./content");
content.cont("nihao"); content.ent("nihao");
1 2 3 4 5 6 7 8 9 10 11
# content.js function cont(cont){ console.log("cont"+cont); };
function ent(ent){ console.log("ent"+ent); };
exports.cont=cont; exports.ent=ent;
1 2 3
# 输出结果 contnihao entnihao
示例4
1 2 3 4 5
# index.js var content=require("./content");
content.cont("nihao"); content.ent("nihao");
1 2 3 4 5 6 7 8 9 10 11 12 13
# content.js function cont(cont){ console.log("cont"+cont); };
function ent(ent){ console.log("ent"+ent); };
module.exports={ cont:cont, ent:ent };
1 2 3
# 输出结果 contnihao entnihao
require.main()
When a file is run directly from Node.js, require.main is set to its module. That means that you can determine whether a file has been run directly by testing
1
require.main === module
For a file foo.js, this will be true if run via node foo.js, but false if run by require('./foo').
Because module provides a filename property (normally equivalent to __filename), the entry point of the current application can be obtained by checking require.main.filename.
Process
process.argv()
Added in: v0.1.27 An array containing the command line arguments. The first element will be ‘node’, the second element will be the name of the JavaScript file. The next elements will be any additional command line arguments.
Error: listen EADDRINUSE :::8888 at Object.exports._errnoException (util.js:856:11) at exports._exceptionWithHostPort (util.js:879:20) at Server._listen2 (net.js:1227:14) at listen (net.js:1263:10) at Server.listen (net.js:1359:5) at Object.start (/home/xuefeng/node/rumen6/server.js:24:32) at Object.<anonymous> (/home/xuefeng/node/rumen6/index.js:10:8) at Module._compile (module.js:413:34) at Object.Module._extensions..js (module.js:422:10) at Module.load (module.js:357:32)