ããããã¯ãŖããããããīŧ
~/test
ãäŊæĨããŖãŦã¯ããĒãĢã ~/test/test.*
ã¨ãããšã¯ãĒãããåŽčĄããã¨ã ãčãã
ãžã㯠bash
~/test$ cd ~/test
~/test$ mkdir src
~/test$ echo '
echo $PWD
cat thefile
' > src/test.sh
~/test$ echo "base" > thefile
~/test$ echo "base/src" > src/thefile
~/test$ bash src/test.sh
/home/cympfh/test
base
ããã¯ã¤ãžãããšã¯ãĒãããäŊæĨããŖãŦã¯ããĒãĢãŗããŧããĻããåŽčĄããã¨čããĻåãæåã§ããīŧ
cp src/test.sh .
bash test.sh
(ããã¯ä¸ã¨åãæå)
src/library.js
ãčĒã (require) ãšã¯ãĒãã src/test.js
ãã äŊæĨããŖãŦã¯ããĒãã åŧãļīŧ
// src/test.js
fs = require('fs')
cat = require('./library.js').cat
cat('thefile')
console.log(fs.readFileSync('thefile', 'utf8'))
cat_the_file = require('./library.js').cat_the_file
cat_the_file();
// src/library.js
exports.cat = function (path) {
console.log(fs.readFileSync(path, 'utf8'))
};
exports.cat_the_file = function () {
var path = 'thefile'
console.log(fs.readFileSync(path, 'utf8'))
}
~/test$ node src/test.js
base
base
base
ã¤ãžããrequire
ãŽä¸ãĢæ¸ããį¸å¯žããšã ãã ãšã¯ãĒããåēæēãĢč§Ŗéãã ããŽäģãŽããšã¯äŊæĨããŖãŦã¯ããĒãåēæēãĢããīŧ
åēæēįšãŽéãį¸å¯žããš ãįšãäē¤ããĻæ¸ããŽãæ°æãĄæĒãīŧ
ãĒãĢããã vim ãŽããščŖåŽãä¸æšãåŠãå ´åãĢ㯠ããä¸æšããŠãããĻãåŠããĒããŽãä¸äžŋã§ããīŧ