NodeJS is designed to build scalable network applications and is typically combined with Express.js for rendering the user-interface, but in this post we will see how to get NodeJS configured with Oracle JET.
Being completly new to NodeJS, I wanted to build something other than the "Hello World" application that you find everywhere on the web. So, after reading an article published by Oracle's A-Team (Oracle JET - with NodeJS) I finally had something exciting to work with. Create an Oracle JET + NodeJS application and use the NodeJS container available from Oracle's Application Container Cloud Service (ACCS).
Note: The next section of this blog will explain the steps for confinguring NodeJS to work with Oracle JET, but if you want to start working with a pre-configured application you can download it from the AMIS Blog.
First, we need to install the Express JS generator.
Next, navigate to the newly created directory called oraclejetwithnodejs. If you try and run the application now with npm start, you will probably see an error that reads "Cannot find module 'express'". This makes sense because Express has not been installed in this project, all we did was create the scaffolding. So let's get everything we need to run our application by running npm install.
At this point, we have our applicaiton and dependancies in our project, so let's try and run it by executing the start command.
Now, open a browser to http://localhost:3000 and you should see that ExpressJS is handling our request and presenting us with a page.
Once the project is created, we need to include the Oracle JET libraries. Assuming the Oracle JET Yeoman generator is already installed on your machine run the following command:
If you need to install the generator, check the Oracle JET Getting Started article for more details. Essentially, we need to install Yeoman, Bower and Grunt-cli.
I typically use the --template=blank option because it is the most basic. Navigate to the project created by the oraclejet generator, go to the 'web' directory, and copy the css and js/libs to the public folder of your oraclejet_node project. Now let's try to start our NodeJS applciation again using npm start. If all goes well we should see the following:
Now that we have our application, let's deploy it to our NodeJS container in Oracle's Application Container Service (ACCS). ACCS has self-service provisioning of Java SE, NodeJS and PHP runtime application containers. For our application, let's select NodeJS as our container from the ACCS service console.
For a detailed tutorial of deploying a NodeJS application to ACCS, take a look at the blog entry by AMIS . One thing to note is that the node-oracledb Database Driver is automatically available to your NodeJS application. This module connects your application to an Oracle database and does not need to be declared in the package.json meta-file because it is available out-of-the-box.
You may also want to interact with your ACCS instance via REST. Using the ACCS REST APIs you can get information on the health of your application, create an application and essentially manage all aspects of the application life cycle.
Here is a quick example using PostMan. The request needs to have the X-ID-TENANT-NAME header, which is the identity domain for your Oracle Cloud instance.