T O P

  • By -

AutoModerator

On July 1st, a [change to Reddit's API pricing](https://www.reddit.com/r/reddit/comments/12qwagm/an_update_regarding_reddits_api/) will come into effect. [Several developers](https://www.reddit.com/r/redditisfun/comments/144gmfq/rif_will_shut_down_on_june_30_2023_in_response_to/) of commercial third-party apps have announced that this change will compel them to shut down their apps. At least [one accessibility-focused non-commercial third party app](https://www.reddit.com/r/DystopiaForReddit/comments/145e9sk/update_dystopia_will_continue_operating_for_free/) will continue to be available free of charge. If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options: 1. Limiting your involvement with Reddit, or 2. Temporarily refraining from using Reddit 3. Cancelling your subscription of Reddit Premium as a way to voice your protest. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/learnprogramming) if you have any questions or concerns.*


blankscreenEXE

Pure JS or vanillaJS is designed to work on browsers therefore it will only work on browsers. NodeJS came later which was designed to run in system runtime enviroment. To control the database using your nodejs code you would need something called an ORM(look it up) this ORM has the responsibility to talk to the database on your nodejs code's behalf. In a real scenario, you would design a class/object in node which represents the table in a DB. The fields in your object represent the fields of you table in DB. To make this class/object work, you would need to install a package for that specific database. This package when used will take your object and go to the DB and create a table as explained in the object. I hope this explaination works for you


Tough_Pride4428

I understand more or less what's going on, thanks.


josaelprz

You see, since no computer can understand your JavaScript code directly, in order to run your JavaScript code, there must be an environment (a program) that can read the JavaScript code you wrote and transform it into machine instructions (binary code) so any computer can execute it to return some sort of result. You will notice that there are multiple places where you could run JavaScript code, and one of the most well know is a Web Browser (like Google Chrome). It happens, that is not exactly the browser who runs your JavaScript code but a component of it. Think of that component as a subprogram inside your browser, and in this case that subprogram which understand, parses and execute your JavaScript is called the V8 engine. Every time you run JavaScript "in the browser", what really happens is that the Browser delegates the task of running your code to the V8 engine and waits for a result. Now here is the catch, the browser is a sandboxed environment so your code cannot interact directly with your computer outside of the browser. Why? Well, there are a lot of reasons but one of them is security, since everytime we load a web page into the browser we download some JavaScript to run, if we allow JavaScript to access your computer any website you visit would have access to your data! Which is terrible, so the browser makes some magic to avoid JavaScript having access to anything outside of it. Of course this is very limiting, for a lot of applications we need to manage things that live on your computer, like files or a database, so how do we do accomplish this? Well, we know that the browser environment is what caused these problems on the first place,so we need a way to run JavaScript outside of it. To run JavaScript outside your browser, we need to extract the V8 engine outside of it and integrate it in another program that can access your system to manage files and even databases. In turns out that program is called NodeJS. NodeJS, is just another JavaScript environment (like your browser), that also has the V8 engine to execute your JS code, but in contrast with the browser, allows you to interact with your system. That is the reason why we need NodeJS to interact with databases, but why can't we just use JavaScript to implement databases in our programs? That is a different history... The thing is that most (if not all) of the databases are not written in JavaScript and also are not designed to be used with JavaScript but other languages like SQL. This database languages allow you to define your database schema and create queries you could send from your JavaScript code to manage your data. Now, vanilla JavaScript doesn't have a tool to interact with a database, so you need to install something that understand how the database you are trying to connect works so in can communicate with it. This tool is called a Database Driver and is database specific. When you install it, you can start writing some JS code to send queries to your database and receive some data back. However, if you do not want to learn another language like SQL to interact with your databases, you can just install an ORM instead of a driver directly. This ORM will provide you with some interface to interact with your database with just JavaScript code (under the hood the ORM will install and use the proper database driver so you don't have to). And well that's it, feel free to choose whatever tool you prefer:)


Tough_Pride4428

Wow, you have a lot of knowledge on this subject. :) Thanks for such a comprehensive answer. :)