# Ember Data and file:/// urls (specifically within NodeWebkit)

**URL:** <https://discuss.emberjs.com/t/ember-data-and-file-urls-specifically-within-nodewebkit/4809>\
**Category:** Uncategorized\
**Created:** [April 8, 2014, 5:24pm UTC](https://discuss.emberjs.com/t/ember-data-and-file-urls-specifically-within-nodewebkit/4809 "2014-04-08T17:24:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![commadelimited](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/commadelimited/32/3548_2.png) [@commadelimited](https://discuss.emberjs.com/u/commadelimited)\
**Post date:** [April 8, 2014, 5:24pm UTC](https://discuss.emberjs.com/t/ember-data-and-file-urls-specifically-within-nodewebkit/4809/1 "2014-04-08T17:24:19Z")

</div>

I’m building an Ember app within the NodeWebkit framework. When I started it I decided to use plain Ember.Object for my Models:

```
App.Person = Ember.Object.extend({
    First: null,
    Last: null
});

```

Then I have a loadData method which reads a JSON file using Node, parses it, and returns the data to the page for Ember to iterate over it.

Now I’d like to start using Ember Data. When I implement the model hook in my route:

```
App.PeopleRoute = Ember.Route.extend({
    name: 'people',
    model: function(){
        // debugger;
        return this.store.find('person');
    }
});

```

The AJAX call fails because it’s pointing at `file:///people` instead of a legitimate resource. I know that I can specify a URL in my Adapter, which currently looks like this:

```
App.ApplicationAdapter = DS.RESTAdapter.extend({
    namespace: 'api/1'
});

```

But that merely pushes the issue down the chain. Is there any way I can reference a file URL relative to my application in which Ember Data could access this JSON file?

I should say that the current approach I’m using works perfectly. The main reason I’m wanting to move to Ember Data is so that I can experiment with the new testing methods.

Would love some advice and input.

---

<div class="post-metadata">

**Author:** ![commadelimited](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/commadelimited/32/3548_2.png) [@commadelimited](https://discuss.emberjs.com/u/commadelimited)\
**Post date:** [April 8, 2014, 5:53pm UTC](https://discuss.emberjs.com/t/ember-data-and-file-urls-specifically-within-nodewebkit/4809/2 "2014-04-08T17:53:18Z")

</div>

Looks like this SO post might do the trick:

> <https://stackoverflow.com/questions/20883902/how-to-retrieve-models-from-json-file-in-ember-js>

Specifically this bit:

```
App.ApplicationAdapter = DS.RESTAdapter.extend({
  // ...

  suffix: '.json',

  pathForType: function(type) {
    this._super(type) + this.get('suffix');
  }
});

```

In my case it looks like this:

```
App.ApplicationAdapter = DS.RESTAdapter.extend({
    namespace: '',
    suffix: '.json',
    pathForType: function(type) {
        // explicitly read from the file system
        var root = nwGui.App.dataPath,
            path = '/%@/%@%@'.fmt(root, this._super(type), this.get('suffix'));
        return path;
    }
});

```

NodeWebkit has a built in property which evaluates to the directory where the application code lives. So the above `pathForType` method would evaluate to:

`//Users/amatthews/Library/Application Support/directory/people.json`

---

<div class="post-metadata">

**Author:** ![ben\_periton](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/ben_periton/32/15683_2.png) [@ben\_periton](https://discuss.emberjs.com/u/ben_periton)\
**Post date:** [April 9, 2014, 5:36pm UTC](https://discuss.emberjs.com/t/ember-data-and-file-urls-specifically-within-nodewebkit/4809/3 "2014-04-09T17:36:20Z")

</div>

Are you using the app protocol?[https://github.com/rogerwang/node-webkit/wiki/App-protocol](https://github.com/rogerwang/node-webkit/wiki/App-protocol)

---

<div class="post-metadata">

**Author:** ![commadelimited](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/commadelimited/32/3548_2.png) [@commadelimited](https://discuss.emberjs.com/u/commadelimited)\
**Post date:** [April 9, 2014, 7:03pm UTC](https://discuss.emberjs.com/t/ember-data-and-file-urls-specifically-within-nodewebkit/4809/4 "2014-04-09T19:03:04Z")

</div>

> [@ben\_periton](#):
>
> [App protocol · nwjs/nw.js Wiki · GitHub](https://github.com/rogerwang/node-webkit/wiki/App-protocol)

I am not. I didn’t even know that was an option. Hasn’t been in any of the articles/tutorials I’ve read. Thanks Ben!
