Making asynchronous (node.js) in Meteor - node.js

Some questions about Meteor and node.js:
Meteor is based on node.js, but can we do node.js IN meteor? (or use it with meteor?)
I would like to combine the power of two and make this (for exemple): http://www.youtube.com/watch?v=EqWD1WGrdjw, in/coupled with meteor...
Is this possible?

I'm assuming you want to do async stuff. You need to use Fibers (node-fibers) inside Meteor. There are great screencasts from cmather explaining them:
http://www.eventedmind.com/posts/nodejs-introducing-fibers
http://www.eventedmind.com/posts/nodejs-using-futures

Related

node.js package written in rust to perform db queries - how to make it efficiently?

I'm a rust newbie, want to write a node.js package related to database querying.
I'm using napi-rs for the package.
In node.js we have own async stuff, in rust we have similar thing called "tokio" for async stuff.
I want to create ORM for node.js, and learn rust at the same time, so idea is to construct queries on node.js side and perform them on rust side, give response back to node.
I see two ways:
Use tokio with tokio-postgres
Not to use tokio, instead to write own database adapter library which will rely on node async functionality and node sockets. Not even sure if I can do this but can try. Not sure if that makes sense.
First way is way more simple, but will it work? Is efficient to include tokio to node.js package?
execute_tokio_future method of napi works just perfect! Details on how to use it I found here: https://forum.safedev.org/t/adventures-in-rust-node-js-and-safe/2959/10
I was able to get benchmark with better results using rust addon than a node library, so the idea paid off.

Write nodeJS Resful services without middleware framework

I want to write node restful API services with MongoDB with out express or hapi.js any middlware js, where do I start from, I have expertise of using JavaScript and no idea about node or middleware?
There is a good reason why people use frameworks like happi or express for node, the most important being that they don't want to reinvent the wheel again.
While you can certainly do it, it is strongly discouraged. Your code won't be as tested, as safe nor as clean as the code of a framework with years of existence and millions of users.
Still, if you insist, your first step should be to get familiarized with the extensive documentation of Node.js:
https://nodejs.org/dist/latest-v9.x/docs/api/
You will need a mix of a great part of those modules so ... good luck and have fun I guess?
I would suggest the URL module as a start point ...

How can I connect my Node.js application to MongoDB without using native modules?

We can accept 20 times slower to avoid using python or C++ in our project. Are there a native module that still works?
There is no need to invent wheel. mongodb package is the simplest one
But if You insist there are many ways:
Easy way: You can use Rest API of mongo and do requests to it using request package
Moderate way: Open mongodb-core package and copy out what You need most, make Your own mongodb class.
Moderate way #2: fork mongodb package, manipulate it and save with new repository name
Hard way: If You want go hardcore (: read mongodb protocol and operate with it using net package to open socket connection to mongodb server.
How about Crest? It's a node wrapper around the MongoDB server that provides a REST API. With it you could talk to MongoDB over REST instead of with a native client, similar to CouchDB.
There are some other utilities listed here. Maybe you're okay with using Python outside of your app but in front of MongoDB to provide the REST API? If so then maybe those are some alternatives if you don't like Crest. Haven't used it myself so I can't vouch for its quality, but it is listed on MongoDB's own list so hopefully it's decent.

Node.JS Working Techniques

I am very curious about how node.js works. I have downloaded node.js but I have no idea how to use it. Does node.js work with XAMPP and MYSQL?
Node.js is itslf act as the XAMPP server,Its a platform not the language. You have to write code in JS and run that code on NOde server.
You can can use MYSQL,MongoDB, etc.. with node code as a DB.
Before jumping to Node.js try basic JS scripting and learn what is missing in normal JS then get your hands dirty with Node.js
Start with learning : non blocking IO model, event loop and higer odder functions.
watch this video for better understanding.
Best of luck!
Keep posting Questions :)

An entire website with node.js and mongodb?

I've build several websites using PHP and mySQL as backend, and believe that I'm fairly familiar with both. However during research for my new website I've come across node.js and mongodb (and socket.io, since the site is gonna contain a chat).
I've decided to use node.js and mongodb to run the chat - but don't know if I should just do the entire site with those two things?
Since I'm gonna run a node server anyway should I just run another (seperate) one hosting the website? Or is that an bad idea? - is it stable?
I could do the programming in PHP and still be using mongodb - but wouldn't node be way faster?
And another question:
I've planned to use ajax to handle all the posts to the page - but since I'm allready using socket.io to the chat - should I do all my post request using that?
For the ajax I've planned to use jQuery (also for all frontend effects).
don't know if I should just do the
entire site with those two things?
If you want to learn node.js then there is nothing better than coding it.
Since I'm gonna run a node server
anyway should I just run another
(seperate) one hosting the website?
You can use existing server and run your node.js app on other free port(o). I think for learning node you don't need to have dedicated machine.
is it stable?
Even versions of node.js are stable releases, however until there is 1.0 with feature freeze there could be breaking changes to its API.
I could do the programming in PHP and
still be using mongodb - but wouldn't
node be way faster?
It most probably (and definitely) would.
I've planned to use ajax to handle all
the posts to the page - but since I'm
allready using socket.io to the chat -
should I do all my post request using
that?
I would recommend stick to MVC model and use express since you can get into lot of time consuming troubles if you would use socket.io for classic stuff. Socket.io is namely for real-time functionality and things related to that.
There are already some solid web frameworks for node.js, in particular check out Express. Here's a really good article outlining some lessons and experiences from building a node.js website:
What it’s like building a real website in Node.js
Regarding your second question, it's probably still best to use AJAX handlers and HTTP with jQuery. I'm not sure that jQuery supports callbacks over raw TCP sockets.
node.js + express + jade + stylus + jQuery is my preferred environment.
Using forever to auto restart the server I've never had any real up-time issues even when I have bugs crashing the server on a regular basis.
As for socket.io + jQuery, they do get along fine, but it's just not as natural as the express + jQuery combo. I'd stick to making ajax calls for most things.
Node.JS can still be a little wild west like, but its improving. It is a very different model from coding in php, but it is very well suited for a lot of websites. You'll probably want to do the thin server (expose a REST API and your websocket endpoints) with a fatter client using something like BackBone.js to keep interactions clean.
The big win from doing the whole thing in node is that you will not have duplication of code between php and js for dealing with the DB or any other services required by both. Node.JS is also fantastic at handling tons and tons of concurrent requests.
Good Luck

Resources