在Node.js中的不同路径语法

huangapple go评论80阅读模式
英文:

different path syntax in node.js

问题

1st case:

let arr = require("../country/state/city/index");

let getFiNa = require("../utilities/utils/index");

let getPeopleInCity = (arr) => {
  return getFiNa(arr);
};

console.log(getPeopleInCity(arr));

module.exports = getPeopleInCity;

2nd case:

const ob = require("./exportObject");

我明白你的困惑,"./" 和 "../" 在终端中有特定的含义,但在 JavaScript 模块中也有它们自己的用法。希望这有助于你理解。

英文:

question , some time we use ./ and some time ../

what is the difference

1st case

let arr = require("../country/state/city/index");


let getFiNa = require("../utilities/utils/index");


let getPeopleInCity = (arr) => {
  return getFiNa(arr);
};


console.log(getPeopleInCity(arr));


module.exports = getPeopleInCity;

2nd case

const ob = require("./exportObject");

i am confused between these two syntax ./ amd ../ although i know the meaning in terminal but in JS module cases i am confused , help me to understand

答案1

得分: 3

. 表示在该文件夹中选择文件
../ 表示退出当前文件夹并从上一个或父文件夹中选择

参考下面的图像
./ 表示在同一节点上
../ 表示前往前一个节点
在Node.js中的不同路径语法

英文:

. Means in that folder choose the file
../ means go exit the current dir/folder and select from that previous or parent dir

Take reference from the image given below
./ means on the same node
../ means go on the previous node
在Node.js中的不同路径语法

huangapple
  • 本文由 发表于 2023年6月8日 13:01:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76428737.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定