I try to access to JSON file data using Meteor JS. But I'm unable to access it. Can anybody suggest what I'm doing wrong?
Folder Structure :
myapp project/lib folder - myfile.json
myfile.json:
EJSONObj = {
"first": "John",
"last": "Doe",
"age": 39,
"sex": "M",
"salary": 70000,
"registered": true,
"favorites":
{
"color": "Blue",
"sport": "Soccer",
"food": "Spaghetti"
}
}
Meteor JS :
if (Meteor.isClient)
{
console.log("My JSON File data:"+EJSONObj.age);
}
Error is :
Uncaught ReferenceError: EJSONObj is not defined
Meteor has recently introduced the private directory accompanied by an assets API.
The docs are at http://docs.meteor.com/#assets_getText and what it allows you to do is place your text and binary files in the private directory, they don't get served up to the client, and they are accessible to Meteor on the server side.
Since Meteor take all other JS and CSS resources and bundles them, the private directory is a place for other file types which you need to read and use.
Related
I got the following error: no such as file or directory public/uploads/bae1774e-d6dc-454b-ba63-a4c8c53d3053.png while I'm uploading an image to the server (nodejs) using multer hosted through ZEIT
const multerMultiple = {
storage: multer.diskStorage({
destination: (req, file, callback) => {
callback(null, "./public/uploads"); // I think the problem here
},
filename: (req, file, callback) => {
const extension = file.mimetype.split("/")[1];
const name = `${uuid.v4()}.${extension}`;
callback(null, name);
}
})
};
The configuration above is working perfectly locally, while the node js is running locally
now.json
{
"name": "application-name",
"version": 2,
"builds": [
{ "src": "index.js", "use": "#now/node-server" },
{ "src": "./public/uploads", "use": "#now/static" }
],
"routes": [{ "src": "/.*", "dest": "/index.js" }],
"env": {
.../ env here
}
}
Source View:
Which is mean the public directory is presented
So any idea why I'm getting the presented issue while the node js is hosted? It is something missing in ZEIT now configuration or something related to my code?
It looks like you're trying to upload files to your app, running as a lambda on Zeit.
Zeit works on top of AWS Lambda. AWS Lambda, and thus Now lambdas, offer only very limited writing to the filesystem during execution, but any changes will be lost when execution completes. There is no durability between lambda executions.
Instead, you'll need to write the files to some sort of durable storage, like AWS S3. Here's an example of how you might do that: https://github.com/zishon89us/node-cheat/tree/master/aws/express_multer_s3
I've read and re-read the jade references and a whole bunch of stack overflow questions but I can't seem to figure this out and I think it should be really simple.
So all I want to do is have an object in a JavaScript file, and have that imported into my jade file so I can use the data from the object when generating my html page.
for example:
This would be in a JS file:
var obj = {
firstName: "bob",
lastName: "smith",
age: 109
};
And in my jade I want to do this:
h1 #{obj.firstName}, #{obj.lastName}
h2= obj.age
etc.
This is just a simple example. Any help at all would be much appreciated.
I would simply create the object in my jade but I want the object to be formatted where each item is on its own line (for readability), and jade doesn't currently support that.
On that link someone mentioned a solution that I did not understand at all: "so I accomplished what I wanted by passing in the array in grunt-contrib-jade instead of putting it directly in the template. Also allowed me to get rid of grunt-sed"
I am using codekit to compile my jade into static html, not Node.JS.
This can be accomplished if you translate your object to JSON format.
From the docs on command line arguments:
-O, --obj <path|str> JavaScript options object or JSON file containing it
Example:
user.json
{
"firstName": "bob",
"lastName": "smith",
"age": 109
}
And you would compile your template like that:
$ jade myTemplate.jade --obj user.json
or if you're using Gulp with gulp-jade:
.pipe(jade({
locals: require('user.json')
}))
I am attempting to use the Node.js SDK runtime starter on bluemix with the SQL service and am finding that the code excerpts from the documentation are incompatible with the current version of the Node.js starter code - looks like the app code has been overhauled recently but the documentation on the bluemix site has not.
I am having difficulty in accessing the VCAP_SERVICE credentials using cfenv, which is what the new version of the starter app uses. On the bluemix dashboard I have this:
{
"sqldb": [
{
"name": "SQL Database-nc",
"label": "sqldb",
"plan": "sqldb_free",
"credentials": {
"port": 50000,
"db": "SQLDB",
"username": "user****",
"host": "75.126.***.***",
"hostname": "75.126.***.**",
"jdbcurl": "jdbc:db2://75.126.***.***:50000/SQLDB",
"uri": "db2://user*****:********#75.126.****:50000/SQLDB",
"password": "***********"
}
}
]
}
and I am trying to access the sqldb service credentials as follows:
var appEnv = cfenv.getAppEnv();
var sqlService = appEnv.getService("sqldb");
console.log("user=" + sqlService.credentials.username);
and I have also tried this:
var appEnv = cfenv.getAppEnv();
var sqlService = appEnv.getService("SQLDB");
console.log("user=" + sqlService.credentials.username);
The app is crashing and reporting that sqlService is null. Feels like I am missing something obvious but could use help in figuring out what that is.
Thank you for any assistance,
-Andy
Use the "name" property, "SQL Database-nc".
From the cfenv documentation...
"The spec parameter should be a regular expression, or a string which is the exact name of the service."
I've been trying to create a Smart Package for the SkelJS framework.
The file is being loaded by the browser but when I try and access the object it exports it says its undefined. I'm using the following code in package.js:
Package.describe({
summary: "SkelJS for Meteor"
});
Package.on_use(function (api) {
api.use('jquery', 'client');
api.add_files(['skel.js'], 'client');
api.export('skel', 'client');
});
Also trying to access Package.skeljs.skel returns undefined as well.
In smart.json I'm using:
{
"name": "skeljs",
"description": "SkelJS for Meteor",
"homepage": "",
"author": "Giles Butler (http://giles.io)",
"version": "0.1.0",
"git": ""
}
I know SkelJS has been loaded because it logs to the console no configuration detected, waiting for manual init but then when I try and run skel.init() it returns undefined.
Any help or tips would be really appreciated.
Thanks
Giles
You also need to modify the first line of skel.min.js/skel.js
Within packages variable scoping still applies so you have to remove the var keyword if you want the file to let other files (such as package.js for api.export) access its variables.
The fix would be to change:
var skel=function() ....
to
skel=function() ....
I've been trying to put together a really simple example using Dust.js in the Browser. Although the docs are very good there doesn't seem to be much information on getting things configured in the for browser.
So based on the following JSON data taken from the Linked-In Dust tutorial:
https://github.com/linkedin/dustjs/wiki/Dust-Tutorial#wiki-Show_me_some_Dust
{
"title": "Famous People",
"names" : [{ "name": "Larry" },{ "name": "Curly" },{ "name": "Moe" }]
}
And this template:
{title}
<ul>
{#names}
<li>{name}</li>{~n}
{/names}
</ul>
How can this be sent up for rendering client side in the browser?
I was looking for a browser example of DustJS too since the tutorials don't really mention it.
Here's a repo I created with an example:
https://github.com/ericktai/dust-js-browser
I use duster.js to compile the template. The repo's README.md should describe the basics.
Hope it helps!
Erick
A little bit down on the page you will find a basic example how to compile a template:
Compiling a Dust Template
Basically you just have to call the compile function to register the template.
var compiled = dust.compile("Hello {name}!", "intro");
To use it immediately, execute loadSource to write the compiled template into dust's template library:
dust.loadSource(compiled);
Then you're able to render the template with your JSON-data:
dust.render("intro", {name: "Fred"}, function(err, out) {
console.log(out);
// or maybe with jquery:
$('#container').html(out);
});