abhi
abhi

Reputation: 2148

connection to postgres using node js

I have user registration form with submit button. I want to connect to postgres database when user clicks on submit button. Can I put this code in any other file and not in app.js. IF yes, how to call this code when user clicks on submit button and I am using express

Upvotes: 0

Views: 48

Answers (1)

Faz
Faz

Reputation: 379

You could put the code to establish a connection into a function in another file and export the function. Import the function in your app.js. Assuming your submit action makes an API call, assign the function to the route that handles the call. Something like:

    app.post("/api/submit", functionToConnect)

Upvotes: 1

Related Questions