How to use now - 10 common examples

To help you get started, we’ve selected a few now 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 zeit / now / test / lib / run-build-lambda.js View on Github external
async function runBuildLambda(inputPath) {
  const inputFiles = await glob('**', inputPath);
  const nowJsonRef = inputFiles['now.json'];
  expect(nowJsonRef).toBeDefined();
  const nowJson = require(nowJsonRef.fsPath);
  expect(nowJson.builds.length).toBe(1);
  const build = nowJson.builds[0];
  expect(build.src.includes('*')).toBeFalsy();
  const entrypoint = build.src.replace(/^\//, ''); // strip leftmost slash
  expect(inputFiles[entrypoint]).toBeDefined();
  inputFiles[entrypoint].digest =
    'this-is-a-fake-digest-for-non-default-analyze';
  const wrapper = require(build.use);

  const analyzeResult = runAnalyze(wrapper, {
    files: inputFiles,
    entrypoint,
    config: build.config
  });
github nuxt / now-builder / test / utils / run-build-lambda.js View on Github external
async function runBuildLambda(inputPath) {
  const inputFiles = await glob('**', inputPath)

  const nowJsonRef = inputFiles['now.json']

  const nowJson = require(nowJsonRef.fsPath)

  const build = nowJson.builds[0]

  const entrypoint = build.src.replace(/^\//, '') // Strip leftmost slash

  inputFiles[entrypoint].digest = 'this-is-a-fake-digest-for-non-default-analyze'

  const wrapper = require(build.use)

  const analyzeResult = runAnalyze(wrapper, {
    files: inputFiles,
    entrypoint,
    config: build.config
  })
github omorandi / tiws / test / Resources / app.js View on Github external
else if ('socket.io' === test) {
	var io = require('socket.io'),
	socket = io.connect(uri);

	socket.on('connect', function () {
		Ti.API.log('connected!')
	});
}

// ****************************************************************************************************************
// ****************************************************************************************************************
// example using now.js which uses socket.io which uses websockets

else if ('nowjs' === test) {
	var now = require('now').nowInitialize(uri, {
		// socket.io init options
		socketio: {
			transports: ['websocket']
		}
	});

	now.core.on('error', function () {
		Ti.API.error('error!')
	});

	now.core.on('ready', function () {
		Ti.API.log('now is now ready')
	});

	now.core.on('disconnect', function () {
		Ti.API.log('now disconnected');
github adityab / memecached / app.js View on Github external
db.close();
        process.exit(1);
    }
});

server = http.createServer( function(req, res) {
    fs.readFile('index.html', function(err, page) {
        res.writeHead(200, {'Content-Type': 'text/html'});
        res.write(page);
        res.end();
    });
});
server.listen(8080);

// now.js code
var everyone = require("now").initialize(server, {socketio: {'transports': ['xhr-polling']}});

// publish meme
everyone.now.publish = function(meme) {
    if(meme.name && meme.text.line1 && meme.text.line2) {
        db.collection('memes', function(err, collection) {
            // add a date field and save
            meme.date = Date.now();
            collection.insert(meme, function(err) {
                if(!err)
                    everyone.now.receiveMeme(meme);
            });
        });
    }
};

// retrieve the latest few memes of a name. If there is no name, retrieve a mixture
github chaoscollective / Space_Editor / app.js View on Github external
});
  /*
  var html = "";
  res.send(html);
  */
  res.send(JSON.stringify(nowUsersList));
});
// ------------------------------------------------------------
// ------------------------------------------------------------
var localFileIsMostRecent = []; // an array of flags indicating if the file has been modified since last save.
var nowjs     = require("now");
var everyone  = nowjs.initialize(server);
// ------ REALTIME NOWJS COLLABORATION ------
//var nowcollab = require("../CHAOS/nowcollab");
//nowcollab.initialize(nowjs, everyone, true);
//-------------------------------------------
nowjs.on('connect', function () { 
  //console.log("CONNECT    > " + this.user.clientId);
  this.user.teamID      = teamID;
  if(this.now.teamID != ''){
    this.user.teamID = this.now.teamID;
  }
  //console.log(this.user);
  //console.log(everyone.users);
  //console.log(" >> PROJECT="+this.user.teamID);
  // hack to get out best guess at the user (since now.js doesn't give us the request object or session!);
  var u = {}; //(Auth || {}).getUserFromCache(decodeURIComponent(this.user.cookie['_chaos.auth'])) || {};
  // now populate it..
github webinos / Webinos-Platform / webinos / core / api / vehicle / contrib / vb-sim / vs.js View on Github external
response.writeHead(200, getContentType(filename));
                response.write(file, "binary");
                response.end();
            });
        });
    });
    httpServer.on('error', function (err) {
        // this catches EADDRINUSE and makes sure node doesn't quit
        console.log('verhicle api: error on vehicle sim server: ' + err);
    });
    try {
        // FIXME this fails when this service is loaded more than once on one host
        // as the port will already be taken
        httpServer.listen(9898);
        var nowjs = require('now');
        var everyone = nowjs.initialize(httpServer);
        var _listeners = new Object();
    } catch (e) {
        console.log('The Vehicle Simulator requires the node-module now. You can install it by the following command: npm install now.');
    }
    var gear = '11';
    var tcData = new Object();
    tcData.s1 = 48.5;
    tcData.s2 = 46.5;
    tcData.c1 = 5.7;
    tcData.c2 = 6.1;
    tcData.d = 33.3;
    tcData.m = 11298;
    tcData.r = 456;
    var psrData = new Object();
    psrData.ol = 255;
    psrData.l = 255;
github Flotype / now / examples / express_example / app.js View on Github external
app.listen(8080);
console.log("Express server listening on port %d", app.address().port);


// NowJS component
var nowjs = require("now");
var everyone = nowjs.initialize(app);


nowjs.on('connect', function(){
      console.log("Joined: " + this.now.name);
});


nowjs.on('disconnect', function(){
      console.log("Left: " + this.now.name);
});

everyone.now.distributeMessage = function(message){
  everyone.now.receiveMessage(this.now.name, message);
};
github chaoscollective / Space_Editor / app.js View on Github external
html += "window.addEventListener('message', receiveMessage, false);";
  html += "";
  res.send(html);
  */
  res.send(JSON.stringify(nowUsersList));
});
// ------------------------------------------------------------
// ------------------------------------------------------------
var localFileIsMostRecent = []; // an array of flags indicating if the file has been modified since last save.
var nowjs     = require("now");
var everyone  = nowjs.initialize(server);
// ------ REALTIME NOWJS COLLABORATION ------
//var nowcollab = require("../CHAOS/nowcollab");
//nowcollab.initialize(nowjs, everyone, true);
//-------------------------------------------
nowjs.on('connect', function () { 
  //console.log("CONNECT    > " + this.user.clientId);
  this.user.teamID      = teamID;
  if(this.now.teamID != ''){
    this.user.teamID = this.now.teamID;
  }
  //console.log(this.user);
  //console.log(everyone.users);
  //console.log(" >> PROJECT="+this.user.teamID);
  // hack to get out best guess at the user (since now.js doesn't give us the request object or session!);
  var u = {}; //(Auth || {}).getUserFromCache(decodeURIComponent(this.user.cookie['_chaos.auth'])) || {};
  // now populate it..
  this.user.about       = {};
  this.user.about._id   = u._id || 0;
  this.user.about.name  = u.nameGiven || u.displayName  || this.user.cookie["_username"] || "???";
  this.user.about.email = u.emailPrimary || "anon@chaoscollective.org";
  // -----
github hughanderson4 / smartjs / server / connectionHandlers / groupHandler.js View on Github external
};
    console.log('broadcast message to all: ' + Util.inspectObject(dto));
    if (everyone && everyone.now && everyone.now.eventServerToClient) {
        everyone.now.eventServerToClient('chat.message', dto, serverClientId);
    }
}

// each time a new nowjs group is created, attach to it's leave handler
Nowjs.on('newgroup', function (group) {
    console.log('Nowjs group created: ' + group.groupName);
    group.on('leave', function () {
        notifyGroupRemoval(group, this.user.clientId);
    });
});

Nowjs.on('disconnect', function () {
    var currentClientId = this.user.clientId;

    console.log('disconnect notice, this.getGroups=' + this.getGroups);
    console.log('this.now=' + Util.inspectObject(this.now));
    console.log('this.user=' + Util.inspectObject(this.user));
    console.log('this.groups=' + Util.inspectObject(this.groups));

    this.getGroups(function (groups) {
        console.log('discod user belongs to groups:' + Util.inspectObject(groups));
        for (var i = 0; i < groups.length; i++) {
            notifyGroupRemoval(groups[i], currentClientId);
        }
    });
});

// feature to broadcast the time periodically
github chaoscollective / Space_Editor / app.js View on Github external
var users = filegroup.getUsers(function (users) {
      var foundUser = false;
      for (var i = 0; i < users.length; i++){ 
        if(users[i] != callerID){
          // this looks like a valid user to get the file from. :)
          console.log("Trying to get file from: " + users[i]);
          nowjs.getClient(users[i], function(){
            if(this.now === undefined){
              console.log("Undefined clientId for requestFullFileFromUserID (using local) >> " + users[i]);
              localFileFetch(userObj, fname, fileRequesterCallback);
            }else{
              this.now.c_userRequestedFullFile(fname, callerID, fileRequesterCallback);
            }
          });
          foundUser = true;
          break;
        }
      }
      if(!foundUser){
        console.log("Flagged as changed, but no user with file: "+userObj.teamID+" >> "+fname+" >> FETCHING last saved.");
        localFileFetch(userObj, fname, fileRequesterCallback);
      }
    });

now

The command-line interface for Vercel

Apache-2.0
Latest version published 4 years ago

Package Health Score

59 / 100
Full package analysis