سؤال

I wish to read text from a file in my Meteor app.

I am using Nitrous.io

The app is called 'myApp' and I am using the following code:

var data = Assets.getText('myApp/lib/test.txt');

I get the following error:

Error: Unknown asset: /myApp/lib/test.txt

What is the correct path to my test.txt file in this context?

هل كانت مفيدة؟

المحلول

The path for getText is relative to your application's private subdirectory. So if the file was myApp/private/test.txt, you could read it with Assets.getText('test.txt');. This should be true regardless of the hosting environment.

نصائح أخرى

You can define your path by using the process.env.PWD variable :

var base            = process.env.PWD;
var itemsLocation   = base + '/public/items/';

It should work on Nitrious.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top