Node.js Generated Code
Earlier we mentioned that a collection of files were generated when you downloaded the ZIP archive from TIBCO Cloud™ Integration. Let's examine some of them 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.
Copy
├───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, because you could 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 metadata for your app, such as name and version, and also contains the list of modules that need to be downloaded to make your app work. - The
README.md
file can be used to store documentation for your app. While TIBCO Cloud Integration does not 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 app. By default the server listens on port8000
and that should not be changed.- The
config
folder contains a copy of the API specification that you used to generate this code. The Node.js app uses that copy to carry out some tasks while it is starting. For example, understanding 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 andhandler
code is a best practice. - The
handlers
folder contains code so your app knows how to handle the requests coming in and where to send the request. The handlers are usually generic in such a way that they do not contain any implementation logic about what data to send back. - The
tests
folder can be used to store unit tests. - The
util
folder has a speciallogger.js
file that provides a log function used by your code for generating the correct log format. 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:Copyvar 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 */
Other Notes
- The default port
8000
for the app's API service set in the generated stub code must not be changed - Developers should not modify any part of the
manifest.json
file because modifications could cause deployment or the running of the app to fail. - It is possible to access the file system of the app container, but there is no guarantee how long any files will persist. You are responsible for any housekeeping for the files you generate.