How can I connect Ember.JS with a database? - javascript

I'd like to connect Ember.JS to a persistent datasource.
Ember.JS could manage the main parts of the application. Express.JS could assist to fetch data and save Ember.JS's app data in a database.
I've heard of stores, models and adapters... Honest, it confuses me a lot!
Could anyone explain the ways of connecting Ember to a database (maybe sqlite3)?
Thank you!

Ember.js is a web framework and is not really intended to be connected to a database directly. You should build an API (with express.js and node for example), and connect this API to your database. Then, Ember.js can talk to your API, through ember-data.
If you are building a mobile application, this should help: https://www.npmjs.com/package/ember-sqlite-adapter

Related

Node.js client api key

I have a node.js backend for an ios app that will provide json data to the app. I want to handle client authentication for each app. The users do not need to create an account. I only want to identify the client apps when providing data and save some data for each client on the node server.
How do I handle identifying each app on the server?
If I need to create an API key, how do I handle that?
If there is a way to authenticate the app when the app first accesses the API, how can I create a unique identifier for the app?
Last, what do I need to know before I deploy the node server? Can I get away by just pointing a domain to my router, opening a port and serving the api from there or is it a must to have a web server setup to handle that?
Thank you
You can basically find a lot of blogs posts to get best practices to follow when designing an api. But here is an over all idea
You can create a client key and send it on every api request or add as part of url
Example: api.example.com/v1/users?client=android&version=1.1
Use Middileware. You can either name as to your convenience or have a database to store key value to manage your clients.
Example:
Create a Middleware which does the handling of authentication and API key checker before you forward it to the routes.
android => 0, ios => 1, web => 2
url: api.example.com/v1/users?client=0&version=1.1
There are many ways to create api keys. Here are some of them
UUID - https://www.npmjs.com/package/uuid
Json web token - https://github.com/auth0/node-jsonwebtoken
Oauth - https://github.com/ciaranj/node-oauth
Again, You have a lot of online posts explaining best practices to follow in production. If express.js, You can find best practices to follow here Express Production
This is just an overview. I request you to do a lot of research online and ask a relative more concrete problems you face towards your learning.

Web App that uses a database from a seperate API

I'm in the process of creating a web app and native mobile apps. I've done a good amount of research and the best approach so far is to set up a separate API to handle a shared database between the web app and the mobile apps. Essentially, the database will be seperate from the web app.
For the web app, our stack is going to be React/Rails. I was wondering if someone could clarify ( what is probably really obvious ) how the rails controllers are going to communicate with the separate API ?
How will we render the components from the API database?
I'm probably over complicating things, but I could use some help.

Integrating ExpressJS and MeteorJS

I have an Epress JS rest api that posts values to the mongoDB. I'm wondering if it is possible to integrate Meteor JS to retrieve those values from the MongoDB.
Any thoughts would be appreciated.
Thanks
Meteor's data layer connects to MongoDB, use a normal publish on the server and subscribe from the client. https://www.meteor.com/tutorials/blaze/collections
It won't matter that your Express app updates the db independently - Meteor's reactivity will pick up the changes as they happen.
In meteor for creating REST-API the first choice would be a publish-subscribe call but if you need to make REST-API beyond that you can use 'Restivus' high-level API.
Here is the link

Receive PubNub subscribe message and insert MongoDB database

I'm trying to develop a small system with a easy architecture. In this case I have one simulator that generate random data and publish this data on PubNub. Otherwise, i have too two subscribers: one web based dashboard and MongoDB database.
At this moment, I developed the simulator and the dashboard. The next stage is receive the PubNub subscribe data and insert into MongoDB.
My issue is how I can do this remotely? What is the framework that I should use? I saw many tutorials that start MongoDB DB by terminal on local machine, remotely how this works?
Someone can give me a full explication?
Regards,
Note: I use PubNub JS SDK, my dashboard was developed in HTML, CSS and JS

Jade #{user.username} Partial Page Refresh

I'm using https://github.com/sahat/hackathon-starter/tree/es6 which leverages Jade in an ExpressJS & MongoDB NodeJS environment. My questions is how can I update #{event.location} && #{event.city} in Front-end if they change inside MongoDB in the back-end?
I do not want to refresh the entire website in order for #{event.location} and #{event.city} to be updated in the front-end.
Could someone please explain how to do this or if there is a better way of achieving this? Maybe with Socket.IO or some other way. I'm fairly new to Node, JS, Jade etc and can't even grasp a decent way of refreshing part of the page with JADE....
Thank you in advance for your help ! Kudos
Express/Jade can only render the page once from backend when the HTTP request comes.
If you have to update the data on frontend, you will have to use different strategy depending on how your data is updated.
If your data in the backend is updated via the same frontend or at known time you can use AJAX calls to server and fetch the values intermittently.
If data is updated via a different channel then socket.io would be the way to go. You can emit events from the backend on data change and receive the events on frontend app and update the data fields only using javascript bindings.
If you have too many manipulations of data to be done I would suggest using a frontend framework from the likes of Angular or Meteor.

Categories

Resources