Skip to main content

Create Micro CRUD services for Oracle Database Cloud using NodeJS

I will try to explain, how you can use NodeJS to create mirco services for the tables in your Oracle Database Cloud or on-premise Database.

Complete Github project : https://github.com/sohamda/LeasifyAPIs
You need to do "npm install" to download the node_modules.

Step by Step guide :

1. NodeJS : either 32 or 64 bit.

If you already have NodeJS installed, please check whether it is 64 or 32. Use below command to figure that out :
C:\>node
> require('os').arch()

If you get : 'ia32' , then it is 32 bit installation.

2. Install oracle-db node module

This was a lengthy and time consuming installation for me, because for Windows, it has a lot of pre-requisites. If you are a Mac user, you are lucky. :)
I followed : https://community.oracle.com/docs/DOC-931127
There is also a detailed one in github : https://github.com/oracle/node-oracledb/blob/master/INSTALL.md

3. Config your DB Cloud

Create a user and couple of tables on which we'll write the Microservices.
I created an user with some basic GRANTS


 



Connected to the DB instance via SQL Developer and created 2 tables :



Now we gonna write some CRUD services on both the tables.

4. Lets explain my NodeJS code

This tutorial from Oracle is excellent for starters : http://www.oracle.com/webfolder/technetwork/tutorials/obe/cloud/apaas/node-cloud-REST-DB/nodecloud-RESTDB.html#overview
You should go through it once before you try to understand my NodeJS construction.

JS code:
4i. app.js : Creates a NodeJS server and invokes "./routes/index.js" for REST URI "/" and "./routes/users.js" for URI "/users". All our DB cloud api is in "index.js"
4ii. ./routes/index.js : Defines an API catalogue on "/api/catalogue" and micro services on LEASE_HISTORY and USERS table.
4iii. ./routes/users_crud.js : Defines the CRUD methods for USERS table.
4iv. ./routes/lease_crud.js : Defines the CRUD methods for LEASE_HISTORY table.
4v.  ./routes/dbutil.js : Defines common utility methods for DB operations.



Config files:
4i. manifest.json : Defines the Application Container Cloud NodeJS version and command to start this NodeJS applicaiton. You only need this file if you want to deploy this application to Oracle Application Container Cloud, Otherwise not.
4ii. package.json : Defines application name, command and dependencies.

5. Running this locally:

Run it from command line :



Check in Postman :



6. Upload it in Application Container Cloud :

Follow the next blog on this.







Comments

  1. Developing better communication skills is important for every individual in society. It gives us the chance to express our thoughts and to share our own views about various aspects. It is also the source of building confidence.motivation letter for college

    ReplyDelete
  2. very nice blogs!!! i have to learning for lot of information for this sites...Sharing for wonderful information about the web design and web development.Thanks for sharing this valuable information to our vision. You have posted a trust worthy blog keep sharing.
    Hire Nodejs Developers
    Nodejs Development Company

    ReplyDelete

Post a Comment

Popular posts from this blog

Chatbots and Oracle Cloud Services

Thanks to Oracle A-Team, I had a chance to work with Chatbots.
3 pure NodeJS applications, on couple of Oracle Cloud platforms and Facebook messenger, and my chatbot was running.

Let me explain, the architecture a bit. To start with, following is the simple representation of how it works.

Exception Handling in ADF

This blog will give you an overview on how you can successfully deal with unhandled Runtime exceptions in an ADF application.

This will give you an idea of:
How to catch the unhandled exceptions.Write a separate log file with stacktrace and thread dumps.Redirect the user to an static error page
#1. Catch unhandled exceptions : 

Create a class "MyExceptionHandler" which extends : oracle.adf.view.rich.context.ExceptionHandler. Override handleException() method.

public void handleException(FacesContext facesContext, Throwable throwable, PhaseId phaseId) throws Throwable {
        // this method is going to create a separate file with stacktrace and thread dumps
        writeException(throwable);
        // redirect to error page
        redirectToErrorPage(facesContext);
    }

 Create a folder "services" inside : ViewController\src\META-INF and then create a file named "oracle.adf.view.rich.context.ExceptionHandler".
In the file, add the absolute name of your custom e…

Secure your Node/Express REST APIs using Passport JS

Recently I have been involved in various discussions on how to make the REST APIs as secure as SOAP.
First of all, let me start with a very basic statement, about security, it doesn't depend on your Webservice type, be it REST or SOAP, your design decisions depicts whether they can be made secure or not.
In this example blog, I will use "Micro CRUD services for Oracle Database Cloud" APIs and implement (read attach) Passport's "local" authentication strategy, to make them secure.

Code in Github : LeasifyAPIs with Passport

What is Passport JS? (from Documentation)

Passport is authentication middleware for Node. It is designed to serve a singular purpose: authenticate requests. When writing modules, encapsulation is a virtue, so Passport delegates all other functionality to the application. This separation of concerns keeps code clean and maintainable, and makes Passport extremely easy to integrate into an application.

What are "strategies" in P…