How to connect Next.js to Database? - javascript

I want to make an application "like" Samsung Health that will use massively queries on a Database.
I would like to know if is better create a custom server made in Node.js (using Express.js) rather than use the integrated one in Next. On Next documentation seems to be some differences.
Where I can find other documentation? On Next documentation I didn't find anything that tell me how to proceed.

I solve it. I had to use fetch function and pay attention with the promise. I had to take the body of the post request and tranform it into json file. Obviously it's necessary that both backend and frontend are currently running.

Related

is it possible to built REST API without knowing about frontend for mobiles apps

This could be a silly question but I want to confirm about it. I am a backend Laravel developer and have created my website. Now I want to create mobile mobile apps but have no knowledge of front-end.
Due to lockdown situations I want to use this time to create the backend API for my apps. Now I want to know is it ok or a normal practice to create APIs without knowing anything about front end. (Like is it possible that I just create all the endpoints now that are throwing data in JSON and then the front-end developer will use them to integrate in the front-end? Thanks
P.S: I dont know how the app front-end will look like but I know what data will be needed in each page/view.
I think you can do this easily with graphql.
A Frontend dev and also beginners with Apollo in the frontend can easily introspect and build the stuff.
If you can choose your Frontend stack there is no problem with rest either.
I always do the Frontend first approach.
Mocking the data for graphql types and building the api later seems to me the best workflow ever.
See ya. Much fun with your project
Yes it is possible very possible to do that it would be nice is the API is well documented using postman or swagger for a better experience when frontend engineers want to integrate
Many API's in the world today are never consumed by a browser or app on the frontend, sure it can make life easier knowing why you are building it.
But at the end of the day, a good API is simple and easy to understand. It just allows a developer to fetch data from a system but normally with some idea about each type of request.
For example, if you had an API for a university the endpoints could be as follows:
/pupils => Get/Sets pupil data.
/teachers => Get/Sets teacher data.
/classes => Get/Sets class subjects and references ID's of both Pupils and Teachers.
So if you wanted all the Pupils in a given class you would query the /classes endpoint and then for each Pupil ID you would query the /pupil endpoint.
Sometimes not having a frontend makes the API even more generic because you might think differently when you do not have a frontend.

Using Graphql and Github API to get repository information

I’m new to web development and I’m trying to make a portfolio website for myself. At the moment I’m trying to stay as vanilla as possible. On my homepage I want to grab information from the repository that I last committed to, title, description, commit history, etc. So that anyone who visits my site can see my latest project.
I’ve learned that you can use graphql to interact with the github API to grab this information, and that you can use a simple HTTP request in JavaScript using the fetch function to send a query. My confusion comes in when you start involving authentication tokens and once I have one how to keep it private instead of hard coding it into my website code.
If anyone can explain, it’d be much appreciated
If you confused about how to do that, I suggest taking a look at the example at https://graphql.org/graphql-js/passing-arguments/
If you want to try the GraphQL queries/mutations out yourself, you can try at https://developer.github.com/v4/explorer/
Without knowing what you already tried this is all I can offer.

Creating a node.js server on Azure that will allow AJAX calls from Javascript on the client

I've created a webapp where most of the processing is done by the users browser using Javascript. For it's development I've used locally stored JSON docs but I need to be able store these in an Azure Cosmos DB.
I'm struggling to understand how to create an Azure function where I can do AJAX calls to the function, which is then passed on to the DB. I've been playing with node.js and express but how do you link DocumentDB module and expose that to another module that can provide AJAX requests?
I've tried looking through Microsofts examples but they are huge, pulling in loads of modules and trying to reverse engineer them and understand how they work is almost impossible for a newbie like me. Can any point in the right direction? Happy to learn and read up but I've not found anything on Google despite spending all day looking.
More research (and coffee) today. The way I've figured this out is follow this SkillShare course
Using the code function in Postman (set to JavaScript XHR) will give you the AJAX calls and following the link Marc gave in the comments to my question will allow you to swap the Mongoose package for the DocumentDB package. Then it's just a case of writing functions and a user interface around this.
I'm going to start by building a user interface page for the courses CRUD app as a prototype before looking to translate this to DocumentDB.

Real Time API backend and frontend

I'm starting a project to create a front end and back end API that updates in real time.
I was thinking of making something like a Forex "viewer" of sorts using https://www.coinapi.io my only problem is, I want to make the server and everything and have it fetch data from that api, put it in my own DB, and have the frontend update in real time (i.e. a price drops, and it instantly updates without really a refresh).
I'm wondering if something like this is practical. I think its a great idea and I'm super interested in this.
I guess I would use websockets, but I don't know the first thing about that, my experience is with REST API's.
Any ideas/thoughts would be nice.
The frameworks and resources ill be using are:
Bootstrap
Vue.Js
Chart.Js
Node.Js
Express
CoinAPI
MongoDB
Mongoose
I think Express and Socket.io would be a good solution here. They work really well together and you would have crossbrowser checks and a lot of stuff you get with Socket.io out of the box. If you would use your own WebSockets you would have to write all this stuff, which is also a good thing if you know what you are doing.
It can work really well and fast, of course it always depends how well you write your code. But the idea will work fine.
Here you have a beginner friendly tutorial for socket.io:
https://www.youtube.com/watch?v=tHbCkikFfDE
And here is one with MongoDB: https://www.youtube.com/watch?v=8Y6mWhcdSUM

Django - Live update with javascript

Here is current workflow:
In django admin someone adds data to model/form.
That starts
python code which runs completely in background and can take up to
5min to finish. Without console access they can't see what's going
on.
They have to wait and refresh site to see results.
I am thinking about something like displaying "progress"(done this, done that, error here) via bootstrap's notifications (js).
Have hard time wrapping my head around how to get data from python to JS(first time doing this) would appreciate any pointers or useful links.
Edit: I found this video: https://www.youtube.com/watch?v=PsorlkAF83s explains it great detail if anyone will be interested in the same thing.
If you could mention how far you achieve then it will be easy to figure out the answer... Anyway my answer is general at all...
First you have to use signal for tracking the database if any new entry it will activate and trigger your python code...
Secondly the best way to communicate with frontend is websockets and recent Mozilla Support for Django promise websocket into the core.
follow this guide for more info about the django channels

Categories