Any way to use any Database with Vanilla JavaScript?

Hello, I pretty much know the answer but still I have a little bit of doubt and I want to clear it totally.

Is their Any way to use any Database with Vanilla JavaScript? I Googled at first and found an article that showed some code to connect SQL and JavaScript (that code totally went over my head). But it was also mentioned that connecting Vanilla JS with any Database should not be done and avoided in all costs due to security reasons.

At this point I am still learning Vanilla JS and thought of making a simple project like To-Do list which will save data in database… I still have not learnt the others like node and angular.

Edit: So is their really any way/option to connect any database (SQL, SQLite, MongoDB etc.) with Vanilla JS besides learning node and angular.

P.S. I am assuming that we can build database type projects with node and angular.

Please comment.
Thank you.

If this is a learning exercise then maybe there would be more value in doing an exercise in something that vanilla js would actually be used for.

That’s pretty clear and to the point.
If you are needing database access then maybe you should be learning server-side scripting too and learn how to connect to databases the right way, as it’s done in the real world.

1 Like

For years, JavaScript was just a client-side language, and it is just recently that it can be used to connect to a database using javascript frameworks etc. So obviously it has been done and is possible, but I would think that the JavaScript required would be miles beyond the capabilities of even an intermediate JavaScript developer, let alone someone who is just learning the language. I think you would find the learning curve much more manageable if you continued to learn JavaScript and then Node and Angular to do the job you want to do.

1 Like

Thank you Sam and WebMachine.

All Doubts cleared. Topic closed :slight_smile:

Actually @littlebirdy, I think that the topic is still open if others would like to contribute to the discussion. You never know what interesting insights might be provided by others, and this is a topic that might be of interest to users other than you.

1 Like

Note that Angular and node are very different in that the former is a client side framework, while node is a server side runtime environment. Now you can’t connect to a database (which is running on the server) with client side JS directly, not even with Angular or the like. All you can do is send HTTP requests, so you’ll need some sort of CRUD interface on the server (some databases such as CouchDB will come with their own HTTP interface, but it’s still just an interface).

If you want to connect to a database directly, you’ll have to operate on the server, and here the only notable option is node. You might still consider this vanilla JS though, I suppose (as long as you don’t pull additional packages, of course). It’s not a framework, it’s a runtime environment providing some additional API to interact with the file system etc. – just as the browser provides some additional API to interact with the DOM.

1 Like

I guess my terminology was a bit misleading (I have not used Angular or Node myself), and thank you for providing more specific information. But one can fall into the trap when learning a language of wanting to do everything using the basic language itself - I have done that myself. You will get to a point, as others have advised on this forum, when it is really better to use the resources that are already out there to achieve your goal.

A few years ago I wrote a Firefox extension that worked with SQLite.

The SQLite database being a local database (i.e. client-side) not a web hosted database.

As posted by others, for a web hosted database JavaScript can not directly access it but must go to a web hosted file (i.e. server-side) that can access it.

Well you can with node because node is just running vanilla JS on the server where JavaScript can access databases.

You can’t with Angular because Angular is running vanilla JS in the browser where JavaScript can’t access databases without making a call to the server…

Yes Web Machine… I agree with you… Thanks for educating me on that.

And wow … inputs from M3, Mitti and FelGal is so good.

Thank you to all of you… My doubts and paths are cleared :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.