如何获取应用程序使用 typescript 运行的路径? [英] How can I get the path that the application is running with typescript?

查看:17
本文介绍了如何获取应用程序使用 typescript 运行的路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 electron、angular2、typescript 和 neDB 创建一个桌面应用程序.为了能够使用 neDB 创建一个文件"数据库,我想要我的项目的路径.我如何使用 typescript 获得它?

I am trying to create a desktop application with electron, angular2, typescript and neDB.In order to be able create a 'file' database with neDB I want the path to my project.How can I get this with typescript ?

推荐答案

使用 app.getAppPath()

Typescript 是 javascript 的超集,因此您可以像使用 javascript 一样执行此操作,尽管您可能希望声明类型,或在这样做时使用其他 typescript 功能.

Typescript is a superset of javascript so you could do it in the same way you would do it with javascript, though you may want to declare typings, or use other typescript features when you do so.

例子:

const remote = require('remote'), 
      app = remote.require('app');

var basepath = app.getAppPath();

更新 - 这些天你应该使用:

Update - these days you should use:

const app = require('electron').remote.app

获取 app.getAppPath() 的应用句柄.

这篇关于如何获取应用程序使用 typescript 运行的路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆