Salesforce,NodeJS and Heroku

Hello, there! Today, I have a quick and interesting stuff for you to read. It’ about Salesforce,NodeJS and Heroku together. How these can be used for interesting projects and with a quick development time. These days a new JavaScript frameworks are being released every now and then. There are a lot of them and it’s hard to keep a count of them as well. Any ways will jump on to the topic, Salesforce,NodeJS and Heroku, now. Let’s start with a little introduction of the Node and Heroku before we proceed.

Node.JS

Node.js is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world.Node.js is an open-source, cross-platform JavaScript run-time environment for executing JavaScript code server-side. Node.js enables JavaScript to be used for server-side scripting, and runs scripts server-side to produce dynamic web page content before the page is sent to the user’s web browser. You can find details about Node.JS at https://nodejs.org.

Heroku

Heroku is a cloud platform that lets us build, deliver, monitor and scale apps. Heroku is a cloud Platform-as-a-Service (PaaS) supporting several programming languages that is used as a web application deployment model.Heroku was acquired by Salesforce.com in 2010, to give it a wing. Hero was I think the first cloud platform to provide the Platform As A Service (PaaS). Initially it was only used with Ruby Programming Language. But later it added support for many other languages such as :

  • Node.js
  • Ruby
  • Java
  • PHP
  • Python
  • Go
  • Scala

You can go to the link Getting Started on Heroku with Node.js to setup your system to work with NodeJS and Heroku. It’s a pretty simple setup process that has been very nicely explained there. Once you are setup with these we can go to the next step for working with Salesforce Data.

Once everything is setup as per instruction, you can run the app mentioned in there as a local app using : Heroku local command in the command prompt and you should see the command screen like the below:heroku local

This tells us that the app is not running at port 5000 and you can go to localhost:5000 to run it.

Connecting Salesforce to NodeJS

In this section I am going to talk about the Salesforce part, well there is nothing much to talk all the code is there in the Git repo. I have uploaded all the code in my Git Repo. The project link is Node-force Feel free to download and modify and add your changes to the build. More than happy to assist if I can be of any help there.

Once you download the repo and setup locally, you can run to get a screen similar to the below. The code from my repo will have all the files needed for this article,Salesforce,NodeJS and Heroku.:
local nodeforce

You can also refer to the hero hosted version at Heroku Node-Force.

Once you land on this page, you will see the login screen as below:

NOTE: You might be required to add your security token at this page for login.

Once logged in this page will show the 10 account records from the connected Salesforce org. This is just a dummy app as of now. We can add pagination and things like that later.

You can click on Create Account to create a new record in your org.

The code

Let me share something about the code files, which are important for this article ,Salesforce,NodeJS and Heroku.

Tough all of the files and folders are important. All the modules of nodeJS can be found in node_modules folderThe important file in there is the package.json file. This file holds the dependencies, which in this case tells us what components or modules we are using in this project. Below is a excerpt from the file and here you can see we have used Body-parser for parsing the JSON response, jsforce: the salesforce nodejs wrapper, which handles most of the complex operations for you, such as login, DML , query etc.,Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications, EJS is a simple templating language that lets you generate HTML markup with plain JavaScript.

“dependencies”: {
“body-parser”:””,
“jsforce”:””,
“pg”: “6.x”,
“cool-ascii-faces”: “1.3.4”,
“ejs”: “2.5.6”,
“express”: “4.15.2”
},

The index.js file contains the redirection and logic to connect the modules. The View folder contains the pages or the templates used in this projects. The view pages are using ejs code. Also, bootstrap is used for look and feel.

Conclusion

Hope this article,Salesforce,NodeJS and Heroku, and related git code will help you start it. As I said, you can contribute in any way you want to the repo and we can share any issues you might find and would like to enhance this. Keep reading and sharing…


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *