![]() ![]() For the demo case the sources are stored in a Git repository, therefore also a classic “.gitignore” file exists. For instance the “node_modules” folder can be excluded from the upload because the step to prepare the environment downloads the npm packages defined in the package.json file. That means all files/folders listed in that file are not uploaded to the Cloud Foundry instance. Additionally a “.cfignore” file is created which contains all folders/files which have to be ignored by the “cf push” command. ![]() In the application root folder the folders “server” and “client” are created to separate the server/client logic from the beginning. host: Host information for the application which is used in the URL which makes the application accessible. ![]() For the demo 128 MB are used.ĭisk_quota: Definition of the disk space available for the application. memory: Definition of the RAM available for the application. The command is executed automatically after the application is successfully deployed to the Cloud Foundry instance.Ĥ. In the example “node app.js” is called which executes the JS code in a file “app.js” which is described later. command: Node.js applications needs a start command to start the application. But from my point of view it is clearer to specify it in the application manifest.ģ. By default an auto determination of the buildpack is done if the buildpack information is missing in the application manifest. It is also possible to reference the buildpack sources on GitHub. buildpack: The name of the Node.js buildpack determined before with command “cf buildpacks”. įollowing information is provided in the file:Ģ. Later information will be added for the MongoDB service consumption. The information is used by the “cf push” command for setting up the environment when the application is deployed to the Cloud Foundry instance. In the application manifest file “manifest.yml”, information about the Node.js application and Cloud Foundry are described. Npm install –save dev express body-parser mongoose cfenv pathĭetails, why they are necessary and how they are used, are described in the following paragraphs.įinally the package.json file looks like following (version numbers of dependencies can be different depending on the point of time installing them): – pathThey can be installed using command The npm packages which are used as dependencies in this demo are: What version of the buildpack is available on the Cloud Foundry instance can be determined using command cf buildpacksThe output of the command displays all available buildpacks including the version information in the file name. In the obligatory “package.json” file the name of the application, the required dependencies to npm packages and the node engine to be used are configured.Īs node engine 6.2.1 is used which is supported by the Node.js Cloud Foundry buildpack in version 1.5.15 ( Release v1.5.15 Create the Cloud Foundry based Node.js application structure.To be able to test against a MongoDB instance on the local machine, MongoDB needs to be installed On the local machine Node.js including the Node Package Manager needs to be installed. To inteact with the Cloud Foundry instance via command line the Cloud Foundry CLI has to be installed on the local machine and the connection to the instance has to be established using the commands “cf api” and “cf logon”. To be able to do the implementation steps some prerequisites have to be fullfilled.įirst of all a HCP Cloud Foundry instance has to be created like described here. The main goal was to find out how the information about the MongoDB service instance(s) can be accessed and used within a Node.js application and how the connection to the MongoDB service instance can be established. They are just for testing reasons created. Disclaimer: The following described points are not “high sophisticated” implementations, especially the API and UI5 part. An inoffical name used for such a scenario is NEMO ( Node.js – Express – MongoDB – OpenUI5). So because of the usage of OpenUI5 it is not a classical MEAN stack application, but the principles are the same. For testing reasons I put a simple OpenUI5 application on top which consumes the data from the MongoDB using an API exposed via Express. I was interested how to use Node.js and especially how to connect to a MongoDB Service instance with Node.js. ![]()
0 Comments
Leave a Reply. |