Node.js on TIBCO Cloud Integration
- Getting started
- Prerequisites
- My first Node.js app
- Deploy your first Node.js app
- Test your Node.js app
- Manage your Node.js apps
- Adding dependencies to your app
- Run your app locally
- Understanding the generated code
- Advanced topics
- Best practices
- Resources
Earlier when you generated your Node.js skeleton app in TIBCO Cloud? Integration, it downloaded a zip containing a bunch of files that were generated from the API specification.
Let?s examine some of these files in a bit more detail and talk about where they come from and why they are needed.
The code is generated for use with Express. Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
????hello_world_nodejs_app_1501395218703 ? |???manifest.json ? ????hello_world_nodejs_app_1501395218703 | |???.eslintignore | |???.eslintrc | |???.npmignore | |???package.json | |???README.md | |???server.js ? ????config ? ? ????swagger.json ? ????data ? ? |???mockgen.js ? ? ????greeting ? ? ????{name}.js ? ????handlers ? ? ????greeting ? ? ????{name}.js ? ????tests ? ? ????greeting ? ? ????{name}.js ? ????util ? ????logger.js
The manifest.json
file describes what kind of app this is and is used by TIBCO Cloud Integration to carry out building and deploying your app. You should never modify this file, as you might cause the deployment or build step to fail.
The dot files (.eslintignore
, .eslintrc
, and .npmignore
) are files that instruct the ESLint and NPM tools to ignore certain files and folders. These are useful if you have large Node.js projects and want to make absolutely sure everyone follows the same coding conventions
The package.json
file contains the meta data of your application (like name, version, etc.) and also contains which modules need to be installed to make your app work.
The README.md
file can be used to store documentation of your app. While TIBCO Cloud Integration doesn't show the file anywhere, it can be very useful if you want to store the code in a version control system like GitHub.
server.js
is the main file of your application. By default the server will listen to port 8000
and that must not be changed.
The config
folder contains a copy of the API specification that you used to generate this code. The Node.js app will use that copy to carry out some tasks when it starts (like understand which mock responses it should give).
The data
folder is, usually, the folder where you want to update your code. This folder contains a JavaScript file for each resource and path parameter. Separating out the data and handler
code is a best practice that you can decide to follow or ignore (that choice is totally up to you :)).
The handlers
folder contains code so your app knows how to handle the requests coming in and where to send the request to. The handlers are usually generic in such a way that it doesn't contain implementation logic of what data to send back.
The tests
folder can be used to store unit tests.
The util
folder has a special logger.js
file which provides a log function to be used by your code for generating the right format of logging. This logging format is essential for the log messages to be picked up and displayed correctly in TIBCO Cloud Integration. To use this in all your files simply add the logger as a ?required? module:
var Logger = require('./util/logger'); /* use the right relative path in your code */ ... Logger.log(Logger.LOG_INFO, 'Your log messages here'); /* Four level of logging levels are available: LOG_ERROR, LOG_WARN, LOG_INFO, and LOG_DEBUG */
Recommended Comments
There are no comments to display.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now