How to use cfenv - 10 common examples

To help you get started, we’ve selected a few cfenv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github krhoyt / IBM / bluemix / websocket / server / app.js View on Github external
var ws = require( 'ws' );

// Constant
var BARCODE_REMOVE = 'barcode_remove';
var BARCODE_SHOW = 'barcode_show';
var BUILDINGS_VALUE = 'buildings';
var CHAT_CREATE = 'create_chat';
var CHAT_READ_ALL = 'read_all_chat';
var PETROLPAL_VALUE = 'petropal';
var PHOTOCELL_VALUE = 'photocell';
var TETRIS_DOWN = 'tetris_down';
var TETRIS_JOIN = 'tetris_join';
var TETRIS_UP = 'tetris_up';

// Environment
var environment = cfenv.getAppEnv();
var configuration = jsonfile.readFileSync( path.join( __dirname, 'configuration.json' ) );

// Database
mongoose.connect( configuration.compose );

mongoose.connection.on( 'connected', function() {
    console.log( 'Connected to Compose.' );
} );

// Models
var Chat = require( path.join( __dirname, 'models/chat' ) );

// Web
var app = express();

// Middleware
github rddill-IBM / ZeroToCognitive / Chapter11 / index.js View on Github external
app.use(bodyParser.json({limit: '50mb'}));
app.set('appName', 'z2c-chapter11');
app.set('port', appEnv.port);

app.set('views', path.join(__dirname + '/HTML'));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/HTML'));
app.use(bodyParser.json());

// Define your own router file in controller folder, export the router, add it into the index.js.
// app.use('/', require("./controller/yourOwnRouter"));

app.use('/', require("./controller/restapi/router"));

if (cfenv.getAppEnv().isLocal == true)
  {
    https.createServer(httpsOptions, app).listen(app.get('port'),
        function(req, res) {console.log(app.get('appName')+' is listening on port: ' + app.get('port'));});
  }
  else
  {
    var server = app.listen(app.get('port'), function() {console.log('Listening on port %d', server.address().port);});
  }
/*
*/
function loadSelectedFile(req, res) {
    var uri = req.originalUrl;
    var filename = __dirname + "/HTML" + uri;
    fs.readFile(filename,
        function(err, data) {
            if (err) {
github RuntimeTools / appmetrics-dash / appmetrics-dash.js View on Github external
// for more info, see: http://expressjs.com
var express = require('express');

var nodereport = require('nodereport');
var fs = require('fs');

var http = require('http');
// cfenv provides access to your Cloud Foundry environment
// for more info, see: https://www.npmjs.com/package/cfenv
var cfenv = require('cfenv');

// create a new express server
var app = require('express')();
var server = http.Server(app);
var io = require('socket.io')(server);
var appEnv = cfenv.getAppEnv()
server.listen(appEnv.port);
console.log("port is " + appEnv.port);

var options = {
    host: 'www.google.com',
    path: '/index.html'
  };

app.use(express.static(__dirname + '/public'));
//app.get('/', function (req, res) {
//  res.sendfile(__dirname + '/index.html');
//});

/*
 * Publish the environment data to clients when they connect
 */
github rddill-IBM / ZeroToCognitive / Chapter09 / index.js View on Github external
app.use(bodyParser.json());
app.set('appName', 'z2c-chapter09');
app.set('port', appEnv.port);

app.set('views', path.join(__dirname + '/HTML'));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/HTML'));
app.use(bodyParser.json());

// Define your own router file in controller folder, export the router, add it into the index.js.
// app.use('/', require("./controller/yourOwnRouter"));

app.use('/', require("./controller/restapi/router"));

if (cfenv.getAppEnv().isLocal == true)
  {
    https.createServer(httpsOptions, app).listen(app.get('port'),
        function(req, res) {console.log(app.get('appName')+' is listening on port: ' + app.get('port'));});
  }
  else
  {
    var server = app.listen(app.get('port'), function() {console.log('Listening on port %d', server.address().port);});
  }
/*
*/
function loadSelectedFile(req, res) {
    var uri = req.originalUrl;
    var filename = __dirname + "/HTML" + uri;
    fs.readFile(filename,
        function(err, data) {
            if (err) {
github IBM-Cloud / iot-sensor-tag / subscribe / app.js View on Github external
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//------------------------------------------------------------------------------
var express = require('express');
var sockjs  = require('sockjs');
var http    = require('http');
var mqtt = require('mqtt');
var websocket_multiplex = require('websocket-multiplex');
var path = require('path');
var macUtil = require('getmac');
var cfenv = require('cfenv');
var properties = require('properties');


var appEnv = cfenv.getAppEnv();
var instanceId = !appEnv.isLocal ? appEnv.app.instance_id : undefined;
var iotService = appEnv.getService('iot-sensor-tag');
if(instanceId && iotService && iotService != null) {
  console.log('Instance Id: ' + instanceId);
  start(instanceId, iotService.credentials.apiKey, iotService.credentials.apiToken,
    iotService.credentials.mqtt_host, iotService.credentials.mqtt_s_port);
} else {
  properties.parse('./config.properties', {path: true}, function(err, cfg) {
    if (err) {
      console.error('A file named config.properties containing the device registration from the IBM IoT Cloud is missing.');
      console.error('The file must contain the following properties: apikey and apitoken.');
      throw e;
    }
    macUtil.getMac(function(err, macAddress) {
      if (err)  throw err;
      var deviceId = macAddress.replace(/:/gi, '');
github IBM / cognos-dashboard-demo / server.js View on Github external
// load local VCAP configuration and service credentials
var vcapLocal;
try {
  vcapLocal = require("./vcap-local.json");
  console.log("Loaded local VCAP", vcapLocal);
} catch (e) {
  console.log("Local vcap not loaded");
}

const appEnvOpts = vcapLocal ? { vcap: vcapLocal} : {};

console.log("appEnvOpts:" + JSON.stringify(appEnvOpts));


var appEnv = cfenv.getAppEnv(appEnvOpts);
console.log("appEnv:" + JSON.stringify(appEnv));


console.log("appEnv services:" + JSON.stringify(appEnv.services["dynamic-dashboard-embedded"]));


if (appEnv.services["dynamic-dashboard-embedded"] || appEnv.getService(/dynamic-dashboard-embedded/)) {
  var ddecred;
  // fetch DDE credentials
  if (appEnv.services["dynamic-dashboard-embedded"]) {
    // CF service named "dynamic-dashboard-embedded"
    ddecred = appEnv.services["dynamic-dashboard-embedded"][0].credentials;
    //console.log("cf service dde credentials: " + JSON.stringify(ddecred));
  } else {
    // user-provided service with "dynamic-dashboard-embedded" in its name
    ddecred = appEnv.getService(/dynamic-dashboard-embedded/).credentials;
github rddill-IBM / ZeroToCognitive / Chapter10 / index.js View on Github external
var cfenv = require('cfenv');

var cookieParser = require('cookie-parser');
var session = require('express-session');
var cloudant = require('cloudant');
var myDB = require('./controller/restapi/features/cloudant_utils');
myDB.authenticate(myDB.create, '');
var sessionBase  = require('./controller/sessionManagement');
var sessionStore = Object.create(sessionBase.SessionObject);

var vcapServices = require('vcap_services');
var uuid = require('uuid');
var env = require('./controller/env.json');
var sessionSecret = env.sessionSecret;
var gmailCredentials = env.gmail;
var appEnv = cfenv.getAppEnv();
var app = express();
var busboy = require('connect-busboy');
app.use(busboy());

// the session secret is a text string of arbitrary length which is
//  used to encode and decode cookies sent between the browser and the server
/**
for information on how to enable https support in osx, go here:
  https://gist.github.com/nrollr/4daba07c67adcb30693e
openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
**/
if (cfenv.getAppEnv().isLocal == true)
{
  var pkey = fs.readFileSync('key.pem');
github IBM / global-financing-blockchain / web-app / controller / restapi / features / fabric / Z2B_Services.js View on Github external
* See the License for the specific language governing permissions and
 * limitations under the License.
 */

'use strict';
let fs = require('fs');
let path = require('path');
const sleep = require('sleep');

// const ws = require('websocket');
// const http = require('http');
// const url = require('url');
const express = require('express');
const app = express();
const cfenv = require('cfenv');
const appEnv = cfenv.getAppEnv();

app.set('port', appEnv.port);



/**
 * This class creates an administration connection to a Hyperledger Composer runtime. The
 * connection can then be used to:
 * <ul>
 * <li></li>
 * </ul>
 *
 * @class
 * @memberof module:Z2Blockchain
 */
let  Z2Blockchain  = {
github multihack / multihack-web / app.js View on Github external
socket.on('code/all/serve', function (data) {
        var requester = users[data.userId];
        if (requester && requester.room === users[id].room){
             requester.socket.emit('code/all/serve', data.fileTree);
        }
    });
    socket.on('code/cursor', function(data){
        if (!users[id]) return;
        data.userId = id;
        socket.to(users[id].room).emit('code/cursor', data); //{userId, fileId, {x,y}}
    });

});


var appEnv = cfenv.getAppEnv();
server.listen(appEnv.port);
console.log("Freeing the web at " + appEnv.url);
github eclipse / orion.client / modules / orionode / lib / metastore / mongodb / store.js View on Github external
function MongoDbMetastore(options) {
	this.options = options;
	if (options.configParams.get("orion.mongodb.cf")) {
		var cfenv = require('cfenv');
		var appenv = cfenv.getAppEnv();
		var services = appenv.services;
		var mongodb_services = services["compose-for-mongodb"];
			if(mongodb_services){
				var credentials = mongodb_services[0].credentials;
				var ca = [new Buffer(credentials.ca_certificate_base64, 'base64')];
				mongoose.connect(credentials.uri, {
					useMongoClient: true,
					mongos: {
						ssl: true,
						sslValidate: true,
						sslCA: ca,
						poolSize: 1,
						reconnectTries: 1
					}
				});
			}

cfenv

easy access to your Cloud Foundry application environment

Apache-2.0
Latest version published 4 years ago

Package Health Score

59 / 100
Full package analysis

Popular cfenv functions

Similar packages