How can I get the path that the application is running with typescript?

被刻印的时光 ゝ 提交于 2019-12-18 12:19:19

问题


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 ?


回答1:


Use app.getAppPath()

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.

Example:

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

var basepath = app.getAppPath();

Update - these days you should use:

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

To get the app handle for app.getAppPath().




回答2:


Writing data to the application installation directory is generally a bad idea since the user running the app may not have permission to write files to that directory. What you should probably do instead is create the database file at the location returned by app.getPath('userData').




回答3:


Here is what worked for me:

require('electron').remote.app.getAppPath()


来源:https://stackoverflow.com/questions/37213696/how-can-i-get-the-path-that-the-application-is-running-with-typescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!