Using d3.js, mongoose, mongoDB, express properly - node.js

I'm really new to node.js and I've been reading a lot of tutorials and documentation on node.js, mongoose, mongoDB, Express, etc and I feel I'm still not getting something.
I want to make a website where data is generated by querying mongoDB and then results are returned to browser where it is visualized in d3.js.
I currently have a graph in d3 as a separate JS file (jdriver.js) called in the head of my jade file. My jdriver.js file is very self-contained in that it generates all the buttons, filters, sliders, etc.). However I'm not sure how I could go about, say if I want to apply a filter -> query mongodb -> have mongodb return a JSON data file -> redraws with new data.
And then how to fit all of that within the framework provided by Express?
Would someone be as kind to either point me to some sources or help me out?
Thanks so much.

Related

Can you populate word fields from a react app using pdftron?

I was wondering if anyone could point me towards a solution to my issue with pdftron/webviewer. I am building a MERN app and one of the projected feature is contracts generation. I created my fields in .docx file, loaded it in with webviewer.
I tried:
having my data collecting form on the same page with webviewer and passing data via state. (...yeah)
Tried to separate contract generation page and display (webviewer) page and use localStorage/redux.
Lastly I tried to take advantage of my database, so I created new model/schema and set up the collections that on the form page the contract data gets POSTed into database and then fetches from the webview page. Mongo has a TTL flag to remove every record after 1 minute.
I can console.log(contract.name) but it just won't consistently show as {{NAME}} (consistently because on several ocassions it works..)
Any help is greatly appreciated. Can't provide console errors log/network dont show any.
It seems like you are trying to fill forms with data. You could check out this guide for form filling. PDFTron JavaScript PDF form filling library
This is an live example showing how it would work.
Let me know how this works for you.

Need advice on loading and saving data on tabulator

I want to load data from a table in my DB using PHP.
+ I want to then edit the data and save it back to the table.
I can't seem to find any examples.
The examples load data that is hard coded in the HTML.
I see there is code to add rows and edit - but I see nothing for saving.
I'm hoping someone can help and give me some pointers.
(Apologies in advance if the information is there - I've looked and can't see - it's 2am and I'm not thinking straight!)
Thanks.
There is an example for loading data into a Tabulator table via ajax here
As for saving it back that depends entirely on how you handle things server side.
you can use the getData function on the table to retrieve an array of data from the table
var data = table.getData();
you would then make an ajax request to pass this data back to the server, it would then be up to you how you go about saving this to the database,there are as many ways to do this as there are backend frameworks so it would depend on what you are already using

Sails.js - Get async data from an EJS file

Are there a good way to get async data from an EJS file?
Sails.js only have async methods to get data from a database.
I have a collection of Pages with their associated content Values. In some cases I want to get a specific Value from another Page (e.g.: in a related page module, a navigation module...). And I need to do that server side, to keep the front-end part SEO friendly.
The easier way should be to retrieve all the Pages and Values inside the controller, and then expose a function to my EJS to get the specific data I need. But I really don't want to retrieve each time all the data from a collection.
I'm working on a CMS so I would avoid creating a new controller/view for each specific cases that I will have.
EDIT:
It seems there is no good way to do that, so I reworked my controller to make it a bit more intelligent. It solve my problem for now.
Assuming I understand you correctly....
data is sent to the view by passing an object into the view funciton
return res.view({data: "important data"});
I'm guessing that you want to call a method for some specific data mid-render. Because having all the data ready on the res.view() call is too slow. As far as I know this is not possible. That would almost certainly be "blocking" code.
Best option I could recommend is to grab specific data using ajax on the client after page load. One of the best features of using sails :)

What's a good node.js / mongoose form builder?

From using other frameworks I've gotten used to not building out and mapping forms to db objects manually. Since using node.js and mongoose. I'm looking for a form builder that allows the following:
automatically maps mongoose objects to form fields
handles both 'new' and 'update' use cases
allows class injection around form fields for styling
includes validation
allows one to add custom fields
Does anyone know of any such form builders for node.js, express, mongoose?
I haven't used it, or looked at it in depth, but https://github.com/oJshua/mongoose-forms looks like it may be of interest.
I know this is kind of old discussion but I just wanted to recommend checking out Formage (npm: formage)
https://github.com/Empeeric/formage
Setup is easy and straightforward. You can check it out in matter of minutes and hopefully this can help you.

Using Solr for indexing and search with Mongodb and nodejs

Does anyone have any experience with this particular stack? I'm working on a web project that will eventually contain an extremely large amount of data and was trying to get Solr to play nicely with some simple Mongodb entries but I have found little to no information about it. I found this: http://blog.knuthaugen.no/2010/04/cooking-with-mongodb-and-solr.html which is mongodb + solr + php, but I'm struggling to see how I would use node similarly. Anybody have any insight? I'd greatly appreciate it. If this is a dumb thing to try to implement, feel free to let me know as well!
Found this library: https://github.com/tjgillies/node-lucene
Doesn't look like there is much documentation there but I'll give it a go.
Update:
So a quick fix (not ideal) that worked was to use a Perl module for lucene and then using the child process functionality in Node.js, I was able to insert and search for my data inside of lucene. So for a workaround, it does the trick.
Probably as of Sep 2012, you would want to take a look at this.
https://github.com/lbdremy/solr-node-client
Good documentations http://lbdremy.github.com/solr-node-client/ (though I didnt liked the web fonts used) but seems VERY promising.
This project looks promising: https://github.com/gsf/node-solr. Not a whole lot of docs, but the tests are promisingly descriptive.
Then you would maybe do something like this in your mongoose schema:
schema.pre('save', function (next) {
// this will be triggered when your mongoose schema object is saved
// TODO add to a queue that sends the documents to SOLR in e.g. batches
// of 2000
});
http://mongoosejs.com/docs/middleware.html
I've been wanting to try mongo + SOLR + node but haven't started any coding yet.

Resources