Handle session using Node.js - mysql

I just started learning Node.js and want to handle a session using MySQL database. I want to do it without express or any kind of framework. I searched through google but couldn't manage to get an answer to my query. My present condition of this task is: I designed my .html files, created HTTP server using http module, managed to connect the database, and now desperately want to create a session (when a user logged in) and destroy it.

Related

Secure Database Connection in ElectronJS Production App?

I've recently begun developing with NodeJS and ElectronJS to create some pretty nifty cross platform software. I want to take it a step further and integrate some database functionality.
While I'm aware that there are mysql packages available to install, I cringe at the idea that anybody can just unpack my asar.app file and see all of the connection details, including username, password, database name, table name, and other sensitive content that you really don't want to expose to people clever enough to break into your app's source code.
I've tried searching extensively on solutions to this problem, which I was surprised to find very little about. How do WhatsApp and Slack secure connections to their database if they were also built with ElectronJS?
Any and all resources are greatly appreciated. I basically want to be able to connect to a production server SQL database in an ElectronJS app without leaving some security backdoor to anybody who cracks the ASAR file.
Thank you!!
For this scenario, I suggest you to use a RESTful web service architecture. Basically you need 3 component, RESTful web back end, client application(your electron) and the database service( see the following image ; source:phppot.com) .For this I suggest you to use nodeJS backend and create a webservice using expressJS . You can define Restful (GET, POST,UPDATE, DELETE) API for each services.
For ex: To get some data from your db, you can send a GET request to the following path <yourdomain>:<port>/api/v1/getyoursomthin using your electron app. Your express app process the request and get the relevant data from the data from the database (Tutorial). So your app can get the respond from the server and display to the user. I will add link to some tutorials. You can find and learn more by google :)
Web: Build a simple app using Node JS and MySQL.
Express.js Tutorial: Build RESTful APIs with Node and Express
( source:phppot.com)

How to connect Angular 2 with MySql Database using Nodejs?

I started new project for Retail Shop, I need to connect Angular 2/5 with MySQL Database using Node or any other method. I need Examples for Select, Create, Delete, Update. for now i need to create Login Page.
The only way you can do that is through http requests to the nodeJs server, since Angular runs in the web browser, while node runs on a server (javascript execution environment).
To create an Http service in Angular you can follow this link. In this way the nodejs server will be able to receive the data and be able to process them through a connection to mysql.
Well connecting Angular???
First learn that Angular, front end, does never connect to any database directly (not counting a New England db or LocalStorage as Database).
You need node or any other server side technology and then serve a REST API for providing data to your front end applications. SO actually your front end app in Angular is a complete separate application and your server side application will only connect to DB, handle logic and serve a REST API.
I use Sequelize for easy connecting and writing queries in JSON syntax.
Some more resources:
https://www.sitepoint.com/user-authentication-mean-stack/
https://medium.com/of-all-things-tech-progress/starting-with-authentication-a-tutorial-with-node-js-and-mongodb-25d524ca0359
Full Example app: http://jasonwatmore.com/post/2017/02/22/mean-with-angular-2-user-registration-and-login-example-tutorial
Angular is for your front end.
If you want Angular like syntax / Typescript for the back-end / server, have a look at: nest.
Nest (NestJS) is a framework for building scalable Node.js server-side applications.

Is there a way to connect Angular to node server?

I'm learning Angular (not angularjs) and what I'm trying to do is have a form and store the data entered to sql database and also query some data from database.
I have looked around and I've not encountered a solution for this. I have seen where people connect using http service to get json data. But how do we do it for sql database.
Does angular even have modules that can connect to a server???
Or should I be looking into noSQL database instead of SQL database.
Please help...

Connecting re-frame app to a Database

I'm having a problem with my re-frame application. I can't figure out how to connect it to a local database on my machine.
In other applications I've written, I've had to add the database specifications (username, password etc) into profiles.clj. Should I create profiles.clj and add the location of my database there? And does this mean I have to update the project.clj as well?
Finally, do the queries to the database, such as GET and POST requests, go in db.cljs.
I apologise if these questions are trivial but after reading the documentation several times I am still a little confused
re-frame is a framework for building client-side web applications. You won't be able to do generic database queries as most databases don't support direct access from a browser.
I'm having a problem with my re-frame application. I can't figure out how to connect it to a local database on my machine.
You probably need to create a middle API tier that accepts REST requests from re-frame, and queries the database, returning JSON back to the client.
Finally, do the queries to the database, such as GET and POST requests, go in db.cljs
Those are probably queries to your API tier? They can live anywhere that you would like.
One thing to clarify: re-frame has an app-db that it uses and refers to. This is a client-side database of local state that lives in your application. It doesn't have a connection to the backend, at least not without you writing more code for it. It sounds like you might be confusing these?

Real-time update to NodeJS(MVC, Express), Mysql and Socket.io application

I'm trying to create a real time web application with NodeJS with an MVC layout using the Express framework and MySQL as my back end data store.
The problem that I've run into is that I can't find any good examples or tutorials on how to use Socket.io (or any other web socket platform to pass information in real time from the database to the web application. The specific problem is getting any new update to MySQL on a specific table to pass that information to, so that if new information is added to the database by a second client connection it will update on the first client connection as soon as the information is added.
Does anyone have any ideas on how to get socket.io(or another websocket connection protocol) and mysql to work together to achieve this? Any code example's or pointing me to some websites that have documentation on this topic would be appreciated.
Thank you!