This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const uuid = require('node-uuid'); | |
let guid = uuid.v4(); | |
console.log(`Generated GUID: ${guid}`); | |
res.send({ | |
id: guid | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var message = { | |
GET: 'GET - query parameter name: ' + req.query.name || 'not set', | |
POST: 'POST - Body parameter name: ' + req.body.name || 'not set', | |
PUT: 'PUT - body parameter name: ' + req.body.name || 'not set', | |
DELETE: 'DELETE - body parameter name: ' + req.body.name || 'not set', | |
}; | |
res.send({ | |
message: message[req.method], | |
method: req.method, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const jsonSchema = require('json-schema'); | |
var schema = { | |
"description" : "A geographical coordinate", | |
"type" : "object", | |
"properties" : { | |
"latitude" : { "type" : "number", "required":true }, | |
"longitude" : { "type" : "number", "required":true } | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request-promise'); | |
request({uri: 'https://api.github.com/users/subkitio', json:true, headers: {'User-Agent':'subkit.io'}}) | |
.then(result => this.res.send(result)) | |
.catch(err => { | |
console.error(err.message); | |
this.res.status(500).end(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose'); | |
var Doc = mongoose.models.Doc ? mongoose.models.Doc : mongoose.model('Doc', { message: String }); | |
var db = mongoose.connect(options.TMP_MONGO_URL); // Connect to https://mongolab.com | |
var doc = new Doc({ message: 'New document from subkit.io!' }); | |
doc.save((err, doc) => { | |
db.connection.close(); | |
if (err) return res.status(400).send(err.message); | |
res.status(201).send(doc); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('Hello from a job!'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const rx = require('rx'); | |
let subscription = rx.Observable | |
.interval(60000) | |
.doAction(counter => { | |
console.log(counter + ' Hello from a RxJs 1min interval job!'); | |
}) | |
.subscribe(); | |
this.onCleanup = () => subscription.dispose(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let counter = 0; | |
const CronJob = require('cron').CronJob; | |
let cronJob = new CronJob('0 */1 * * * *', | |
() => console.log(`${counter++}: You will see this message from a cron job every minute!`), | |
() => console.log('You will see this message on cron job done!'), | |
true); | |
//Stop cron onCleanup | |
this.onCleanup = () => cronJob.stop(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Basic EJS-HTML Template</title> | |
</head> | |
<body> | |
<h1>My basic EJS-HTML Template</h1> | |
<p>Counter: <%= state.counter || 0 %></p> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jobparams.counter += 1; | |
run.resolve(`Success! counter: ${jobparams.counter}`); |
OlderNewer