How can I get the path that the application is run

2019-02-07 02:45发布

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 ?

2条回答
地球回转人心会变
2楼-- · 2019-02-07 03:23

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();
查看更多
够拽才男人
3楼-- · 2019-02-07 03:38

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').

查看更多
登录 后发表回答