简体   繁体   English

从服务器获取本地系统主目录路径

[英]Get local system home directory path from server

我有一台正在运行的服务器,我想使用 node js 获取运行 aws 服务器的本地系统文件路径

使用process.cwd()也记录在这里: https : //nodejs.org/api/process.html

This might solve your problem:这可能会解决您的问题:

__dirname

Check with a console log whether it's what you wanted or not.检查控制台日志是否是您想要的。

There are multiple ways of achieving this.有多种方法可以实现这一点。 One of them is you can use this package,其中之一是你可以使用这个包,

app-root-path应用程序根路径

Install the package with the command :使用以下命令安装软件包:

npm i -S app-root-path                   //install the package

Use package where you required :在您需要的地方使用包:

var appRoot = require('app-root-path');  //require package 
console.log(appRoot);                    //use variable as string 

You can import the package and use variable where ever you require inside the app.您可以导入包并在应用程序内需要的任何位置使用变量。 You can check this package documentation visiting this link .您可以访问此链接查看此包文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM