Reactive Code without mongodb in Meteor and using NPM packages with Meteor - meteor

I am playing around with Meteor and I am trying, to connect the serverside of the application to another server S.
Therefore I want to open an TLS client socket and push the received data to the client, every time the server S transmits data.
Now I have two questions:
Can I require node packages in the usual way (e.g. var Candle = require('candle');)?
Is it possible, to create reactive code without writing the received data to a collection, which is stored in the mongodb database?
In other words, I just want to push the data to all clients, without saving it on the server.

1
To require a npm package, you need to install npm package via mrt add npm.
Then you add packages.json file with the list of necessary packages, for example:
{
"candle": "0.4.0",
"oauth": "0.9.11"
}
Afterwards, you can require the package with Meteor.require('candle');.
2
To create a reactive code you use Dependencies – see the documentation. Basically, you create a dep:
var dep = new Deps.Dependency();
mark the functions that should be recalculated when the dep is changed:
Templates.example.something = function() {
dep.depend();
...
}
And then change it when necessary:
dep.changed();

I can only answer your first question.
In order to integrate npm packages, you should add npm package via meteorite and create a packages.json file as documented here: https://github.com/arunoda/meteor-npm
Then you can load npm modules as follows:
var Candle = Meteor.require('candle');

Related

Errors while updating Meteor version

I am trying to update my meteor project from 1.8.2 to the latest version. To do this, I have run meteor update outside of a meteor project and got this message:
The latest version of Meteor, 2.3.6, is already installed on this computer. Run 'meteor update' inside of a particular project directory to update that project to Meteor 2.3.6
After that, I go into my project directory and run the same meteor update and receive this message:
=> Errors while initializing project:
While selecting package versions:
error: No version of standard-minifier-js satisfies all constraints: #2.6.1, #=2.5.0, #~2.6.1
Constraints on package "standard-minifier-js":
* standard-minifier-js#2.6.1 <- top level
* standard-minifier-js#=2.5.0 <- top level
* standard-minifier-js#~2.6.1 <- top level
No version of babel-compiler satisfies all constraints: #=7.4.0, #~7.7.0
Constraints on package "babel-compiler":
* babel-compiler#=7.4.0 <- top level
* babel-compiler#~7.7.0 <- top level
* babel-compiler#7.7.0 <- ecmascript 0.15.3 <- 416serg:simple-text-rotator 0.0.1
I'm not too clear on what the above error message means so if someone could explain that would be amazing. Even better if you've got any tips or ideas to solve this. Please let me know if you need any additional information!
As requested in comment, .meteor/packages:
# Meteor packages used by this project, one per line.
# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
# autopublish
# insecure
accounts-ui#1.3.1
accounts-password#1.5.1
# documentation for iron router talks about a higher version.
# but, example todos and others use 0.9.4 which uses routes without a slash(/),
# and actual url is specified on path property.
iron:router#=0.9.4
jquery
underscore#1.0.10
email#1.2.3
alanning:roles
meteor-base#1.4.0
mobile-experience#1.0.5
mongo#1.7.0
blaze-html-templates
session#1.2.0
tracker#1.2.0
logging#1.1.20
reload#1.3.0
random#1.1.0
ejson#1.1.0
spacebars
check#1.3.1
matb33:collection-hooks
# for stripe mrgalaxy:stripe
mrgalaxy:stripe
momentjs:moment
themeteorchef:jquery-validation
http#1.4.2
# for theme
less
twbs:bootstrap#3.3.5
fortawesome:fontawesome
reactive-var#1.0.11
summernote:summernote
dsyko:meteor-node-csv
#force-ssl
peppelg:bootstrap-3-modal
416serg:simple-text-rotator
risul:bootstrap-colorpicker
tomi:upload-jquery
dangrossman:bootstrap-daterangepicker
hellotech:moment-timezone
agnito:simptip
#abhiaiyer:meteor-twilio
jercle:livestamp
#msavin:mongol
tmeasday:publish-counts
kadira:blaze-layout
standard-minifier-css#1.5.4
standard-minifier-js#2.6.1
shell-server#0.4.0
dynamic-import#0.5.1
tomi:upload-server#1.3.4_3
tsega:mentions
montiapm:agent
mizzao:autocomplete
huaming:js-xlsx
edgee:slingshot
mizzao:user-status
I also have a file .meteor/packages~ (not sure what this is or if it's relevant):
# Meteor packages used by this project, one per line.
# Check this file (and the other files in this directory) into your repository.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
# autopublish
# insecure
accounts-ui
accounts-password
# documentation for iron router talks about a higher version.
# but, example todos and others use 0.9.4 which uses routes without a slash(/),
# and actual url is specified on path property.
iron:router#=0.9.4
jquery
underscore
email
alanning:roles
standard-minifiers
meteor-base
mobile-experience
mongo
blaze-html-templates
session
tracker
logging
reload
random
ejson
spacebars
check
# for stripe mrgalaxy:stripe
mrgalaxy:stripe
momentjs:moment
themeteorchef:jquery-validation
http
# for theme
less
twbs:bootstrap#3.3.5
fortawesome:fontawesome
reactive-var
summernote:summernote
dsyko:meteor-node-csv
#force-ssl
peppelg:bootstrap-3-modal
416serg:simple-text-rotator
risul:bootstrap-colorpicker
tomi:upload-server
tomi:upload-jquery
dangrossman:bootstrap-daterangepicker
It seems that you have all of these in your top-level, i.e., .meteor/packages:
babel-compiler#=7.4.0
babel-compiler#~7.7.0
standard-minifier-js#2.6.1
standard-minifier-js#=2.5.0
standard-minifier-js#~2.6.1
which express version constraints on the named packages. There are no versions for these two packages that satisfy all given constraints. But it seems pretty safe to say that you can reduce this to:
babel-compiler#~7.7.0
standard-minifier-js#2.6.1
but if
babel-compiler#~7.7.0
standard-minifier-js#~2.6.1
works, that would probably save you some trouble down the road, so I would try that first.
If you want to learn more about these constraint expressions, they are Semantic Versioning constraints, i.e., the same as used by npm: https://docs.npmjs.com/cli/v7/configuring-npm/package-json#dependencies.

base32 encode/decode on Meteor platform

For a reason I need to implement base32 encode and decode within the Meteor platform and I am having a very difficult time to find any package available for me to do it. I found one for base64, but not base32. Any pointer?
You can use all npm packages by adding a Meteor package like this one: https://atmospherejs.com/meteorhacks/npm.
Then create a 'package.json' file:
{
"base32": "0.0.6"
}
And you are ready to use the package with Meteor.npmRequire('base32') on the server side.

Meteor 0.9 package publish issue

As per this https://hackpad.com/Migrating-Packages-zN0we9sIjkH I created a new meteor package and currently facing a problem when trying to publish.
PackageName : 'UserId:packageName'
To add package : 'meteor add packageName' (mateor add UserId:packageName did not work).
Package runs locally without any issue.
When I tried to publish,
cd path/to/your:package
meteor publish
Message :
There is no package named 'packageName'. If you are creating a new package, use the --create flag.
Publish failed.
Then I tried "meteor publish --create"
Message :
To confirm that you wish to create a top-level package with no account
prefix, please run this command again with the --top-level option.
(Only administrators can create top-level packages without an account prefix)
I used "UserId: PackageName" when creating the package and already log in to meteor account. Any idea to fix this issue?
Thanks !
Make sure the name field is in package.js:
Package.describe({
name: "user:packagename",
// other fields
});
Then, there will be no need to make sure the package is in a directory with the same name.
See https://github.com/mizzao/meteor-user-status for an example.

Meteor: EJSON is not defined

I'm trying to use a private JSON file to add some simple template documents to the mongo collection if it is empty:
if (Passions.find().count() === 0) {
mockPassions = JSON.parse(Assets.getText("mockups/passions.json"));
_.each(mockPassions.passions, function(passion) {
return Passions.insert(passion);
});
}
I'm getting the error:
ReferenceError: EJSON is not defined
Does anyone have any clue? I'm using Meteor 0.6.5.
Thanks
You need to bring EJSON up to the global namespace via
meteor add ejson
In meteor 0.6.5 unless you explicitly tell it to, packages are namespaced into package
Considering Latest Meteor 1.6, you can follow below steps:
A. First Approach [Independent of the meteor restart/stop/start]
Edit .meteor/packages file and add 'ejson' to end of the file
B. Second Approach
Stop Server if already running by pressing ctrl+c
Run command meteor add ejson
Restart Server using command meteor

How can one parse HTML server-side with Meteor?

I want to be able to scrape links out of an HTML page that I am fetching with the Meteor.http method. Would be ideal to use jQuery on the server-side but I don't think this works.
Consider using cheerio its just like jquery but more for scraping. I have tried to answer this before so I hope I do a better job this time.
its an npm module so first step install it (inside your project dir) with terminal:
meteor add http
cd .meteor
npm install cheerio
So now the code:
You need to use this in your server js/or equivalent
var cheerio = __meteor_bootstrap__.require('cheerio');
Meteor.methods({
last_action: function() {
$ = cheerio.load(Meteor.http.get("https://github.com/meteor/meteor").content);
return $('.commit-title').text().trim()
}
})
If you run this from your client side js, you will see the last action on meteors github branch:
Meteor.call("last_action",function(err,result){ console.log(result) } );
I got this as of today/feb 23rd
which the same as on github.com/meteor/meteor
Use cheerio, as Akshat suggests, but I would recommend a different way of using it, as of now, for Meteor 0.8.0.
First, install npm for Meteor:
$ mrt add npm
Then modify packages.json to (of course you can have different version of cheerio, or other node packages as well):
{
"cheerio": "0.15.0"
}
In server.js (or any other file, in server-side code) start:
var cheerio = Meteor.require('cheerio');
The use cheerio in a way you like.
Upon running $ meteor it will automatically install cheerio.

Resources