I have written many articles on Node.js and AngularJs. In this article, I will demonstrate how to use PostgreSQL with Node.js and deploy on Heroku. I think you already smelled that this is one of starting article which will finally merged with Salesforce to create some cool application.

Assuming you already have some background knowledge on Node.js and Heroku, If not please visit previous articles of this blog or my Slideshare account. Using Angularjs is totally optional and you can use library like JQuery or plain JavaScript.

File -1 is code snippet of “package.json”. After creating this file, you will need to run command “npm install“. This command will install all the required dependencies needed for this application.

File 2, shows how different CRUD operations is performed in “pg” module of node.js. If you notice this file ; we are using “process.env.DATABASE_URL“. This variable will store Database string needed to connect PostgreSQL in heroku, this will be automatically available once you install “PostgreSQL” add-on in your Heroku application. If this variable is not available (like on local system) then we are using actual connection string of PostgreSQL installed on system. you will need to replace this connection string with your credentials.

If you want to create Table schema, you need to hit “/db/createTable” URL and if you want to delete table, hit “/db/dropTable” URL.

File 3 is Node.js starting file, which actually routes all requests. For code modularity, I have separated database operations related code in “File 2” and importing in this file.

File 4, is landing page which calls CRUD functions using ajax with the help of Angularjs.

File 5 – “App.json” which is important for “Heroku 1” button to work in Github. You can ignore this file. This file basically is used by Heroku to directly install this application on Heroku on single click and known as “Heroku Button“.

After series of test, I was able to actually find out the issue. I changed the port number and also I found out that in code I used var dbOperations which is case sensitive. but after changing the file name to which I was using, I was finally able to run the app at server. Thank so much for the excellent post to get introduced to node Js

Thanks for this wonderful article. I’m new to Node/expressJS.
When try i to access external website (salesforce Marketing cloud) using index.html and App.js i’m not able to
1) pass the http request from index.html to App.js 2) hence i have http request code in App.js. 3) i’m able to get the response from SFMC but not able to pass the same to index.html to parse and display.

Thanks for this great article. But, i could not run the passing datas from the html page to database. I test dbOperations with url get requests and it works properly. But, html apge does not call dbOperations. Do you have any suggestions? Should i change sometings in ‘index.html’?