I have tried this code in meteor js but it will display error "TypeError: Object #Object> has no method 'parse'"
path = Npm.require('path')
filename = path.parse('/home/user/dir/file.txt')
but in the documentaion in node js parse method should exisit in path library http://nodejs.org/api/path.html#path_path_parse_pathstring
Any tips?
The docs default to the current version of node, however meteor typically uses and older version. You can determine which version of node meteor is currently running by looking at the changelog. For v.1.0.3.2 it's node v0.10.33. You can access the old docs here:
http://nodejs.org/docs/v0.10.33/api/
As you can see, the older version of path did not have the parse function. You can also see this via:
console.log(_.keys(path));
If you want to know what version you are using, this post will help you :
How can I know the version of node being used by my meteor app?
Related
I'm new to JS and I have problem in my project. I can't load handlebars. I have the same ReferenceError : handlebars is not defined. I've tried also adding handlebars.js file in src folder but it doesn't work. I would appreciate any help. https://github.com/dzgierski19/pizzeria-project
My JS code :
`const templates = {
menuProduct: Handlebars.compile(document.querySelector(select.templateOf.menuProduct).innerHTML),
};`
My HTML
`<script src="https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.1.0/handlebars.min.js"></script>
`
handlebars error
Have you tried to change the handlebars version?
You're using version 4.1.0, but handlebars it's already on version 4.7.7
Theirs any reason to use such an old version?
If you need to use this version, take a look at this version docs to check if it's available and if the methods you're using are right.
At the official doc the say to use #latest version
https://handlebarsjs.com/guide/#installation
I am working on browser based application that makes use of aws-sdk. I am using browserify for my app code but have not figured out how to roll aws into it. I have tried a couple of different approaches:
//MyApp.js - Take 1 using downloaded minified version
var AWS = require ('./aws-sdk.min.js');
...
AWS.config.region='us-east-2';
...
results in Cannot set property 'region' of undefined
My guess is that this doesn't work because browserify does not resolve the minified code.
//MyApp.js - Take 2 using downloaded development version
var AWS = require ('./aws-sdk.js');
This does not compile. Browserify reports Error: Cannot find module '../lib/core'.
Is there a trick to this that I am missing?
When I used AWS in the browser I set my region depending on the service I need, for example:
new AWS.EC2({apiVersion: '2016-11-15', credentials, region})
So this made me wonder, maybe the version you downloaded is encapsulated and not exposing anything for browserify.
First I tested the version in the browser as follows:
console.log(AWS)
<script src="https://cdnjs.cloudflare.com/ajax/libs/aws-sdk/2.184.0/aws-sdk.min.js"></script>
Everything looked good so then I went ahead and tested on browserify.
Turns out you are reassigning the AWS global variable when you do:
var AWS = require ('./aws-sdk.min.js');
But you are already bundling it, so you are good, what you need to do is the following:
require ('./aws-sdk.min.js');
// And then use it happily
AWS.config.region='us-east-2';
Without reassigning the AWS global variable
I'm going to start tagging a codebase using Git tags, but I would also like to display this tag somewhere within my app, so that the testers know which version they are testing.
Is there a way to read what the current Git tag using JavaScript?
FYI, I use Grunt.js to build the app. However, a vanilla JS solution would preferable.
isomorphic-git has a listTags() function that does just that. The package is available as a npm package. Example snippet copied from the API documentation:
let tags = await git.listTags({ dir: '.' })
console.log(tags)
Currently, isomorphic-git does not support creating tags (at the time of writing, the latest release of the package is version 0.37.3). However, there is a GitHub issue implying that the work has been started and it will be added in the future.
Using the git-rev-sync package, you can create a custom task to retrieve the current tag and store it as a grunt.option to use elsewhere in your grunt tasks:
var git = require('git-rev-sync');
function currentGitTag() {
var currentTag = git.tag();
grunt.option('tag', currentTag);
}
grunt.registerTask('gitTag', currentGitTag);
To access the value within grunt: grunt.option('tag');.
You can also access the value via template strings: <%= grunt.option('tag') %>
I am new to pouchdb and nw.js and may be this question is a little bit too simple, (sorry for my ignorance).
I am trying to to use pouchdb in a nw.js project via require() but with no luck.
According to the documentation for the pouchdb setup , under Node.js section, I dit it exactly as it says with no success.
After that I installed leveldown component into the project, and I have followed the following instructions under https://github.com/nolanlawson/pouchdb-nw github project.
So, at this point, I have already done the following:
nw-gyp configure --target=0.12.3 / in the node_modules/leveldown directory
nw-gyp build
Then, according to pouchdb.com/guides/databases.html I have:
var PouchDB = require('pouchdb');
var db = new PouchDB('kittens');
but again with no luck. In addition, by running the following:
db.info().then(function (info) {console.log(info); });
getting no response.
Note: If just include this <script src="../node_modules/pouchdb/dist/pouchdb.min.js"></script>
in the index.html file, everything works like a charm.
nw.js version: 0.12.3 /
pouchdb version: 5.2.1
What am I missing?
Did you try the demo? https://github.com/nolanlawson/pouchdb-nw-hello-world There are quite a few steps to install PouchDB correctly in NW.JS.
Edit: oh wait, yes, you did see the demo already. Maybe the issue is that LevelDOWN is incompatible with your version of NW? In my demo I was using an older version of NW than you.
Yet another option is to use the websql adapter inside of Node, which should give you similar performance to LevelDB while possibly being easier to compile than LevelDOWN. If all else fails, I'd recommend filing an issue on the LevelDOWN repo; they have tons of issues related to building for X version of Node on Y architecture on Z operating system, so your combination of XYZ might be a unique one.
Finally I found a working solution to my problem.
The work-around is as follows:
1) I updated pouchDB to 5.3.0
npm update pouchdb --save
2) Then navigate to node_modules/leveldown
cd node_modules/leveldown
3) configure gyp with nw.js target version
sudo nw-gyp configure --target=0.12.3
4) Build again the nw gyp
nw-gyp build
5) And then in my javascript module file
var PouchDB = require('pouchdb');
var arincPouchDB = new PouchDB('./db/arincAirports'); // new pouch db for node without adapter // means you get leveldb adapter in this case.
var jsonData = require("../datasrc/output/data.json");
arincPouchDB.bulkDocs(jsonData);
arincPouchDB.info().then(function (info) {
console.log(info);
});
6) And the console says...
Objectadapter: "leveldb"
auto_compaction: false
backend_adapter:"LevelDOWN"
db_name: "./db/arincAirports"doc_count: 12
update_seq: 12
__proto__: Object...
Note: If you try to use pouchDB from a script tag in your html file, and at the same time you have to use it in a javascript function, that will be exported via module exports e.g
exports.pouchDBFunction = new pouchDBFunction();
and to use this exported function in another javascript file,
like this
var json2PouchDB = require("./js/pouchDBFunction.js");
json2PouchDB.pouchDBFunction;
will not work and you will get the error pouchdb is not defined. That's why you need to have pouchDB via require() function.
Hope this workaround helps...
I'm attempting to use a jQuery plugin (in this case 'fitText') in an Ember project.
In the ember-cli-build.js (that replaced the Brocofile recently...) - I import the dependency (which I have already installed with bower).
/* global require, module */
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
module.exports = function(defaults) {
var app = new EmberApp(defaults, {
// Add options here
});
app.import('bower_components/fittext/fittext.js');
return app.toTree();
};
In my console, I can type in 'fitText' and I DO get the object back. So, it's global now, and I should be able to use it anywhere. BUT "Uncaught TypeError: $(...).fitText is not a function"
#Tom Netzband pointed out that the bower version of fitText was the one that #adacio maintains and is vanilla JS. I've since switched it out for a app.import('vendor/jquery.fittext.js'); (the JS is really only 20 lines or so)
Previously I needed to import it in the controller or route where I want to use it - but the docs don't reference that anymore. In the docs with moment.js as the example, it seems to become a global.
I've put it in the ready hook in app.js - next to similar jQuery things that work fine... but no luck. In this case I only want to affect a few words on the index.hbs / route
UPDATE
This has really just become another question now. I thought it was still the same problem but it's not. So awarding answer and asking a new one. Thanks.
It looks like bower install fittext doesn't install the jQuery plugin version of fitText, it only installs the plain js version of it.
If you look at your bower_components/fittext/fittext.js file, you'll see jQuery isn't passed in or used, and the example from the example.html file shows usage as being:
fitText(document.getElementById('fittext'), 1.2)
So if you want the jQuery version you might have to download it straight from github and throw it in your vendor folder and include it outside of bower.
UPDATE
Looks like the version registered with bower is a forked version from the jQuery version where jQuery has been removed: https://github.com/adactio/FitText.js
There is in fact a Bower version of the jQuery version of the library.
bower install FitText.js --save
I think Dave Rupert has a jQuery version in his crates as well.
$ bower install jquery-fittext --save