Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Avatar for Testing 20.04.
Download
733 views
Kernel: Javascript (Node.js)
1 + 1;
2
process.version;
'v12.16.3'
[1, 2, 5, 10];
[ 1, 2, 5, 10 ]
function test(x, y) { s = []; for (var i = 0; i < x; i++) { s.push(y + i); } return s; }
test(10, 23);
[ 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 ]
$$.async(); console.log("Hello, World!"); function run() { console.log("I'm done waiting a second."); $$.done(); } setTimeout(run, 1000);
Hello, World! I'm done waiting a second.
const fs = require("fs");
$$.async(); fs.readFile("javascript.ipynb", "utf8", (err, data) => { const nb = JSON.parse(data); console.log(JSON.stringify(nb.cells[1], null, 2)); $$.done(); });
{ "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "2" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "1+1 " ] }
async function a() { console.log("start"); await new Promise((done, fail) => setTimeout(done, 1000)); console.log("done"); }
$$.async(); (async () => { await a(); $$.done(); })();
start done

Little HTTP Server

Open it up at https://cocalc.com/[YOUR PROJECT ID]/server/8080

more info: https://doc.cocalc.com/howto/webserver.html

var http = require("http"); http .createServer(function (req, res) { res.writeHead(200, { "Content-Type": "text/plain" }); res.end(`Hello World!\nIt's ${new Date().toISOString()}`); }) .listen(8080);
Server { insecureHTTPParser: undefined, _events: [Object: null prototype] { request: [Function], connection: [Function: connectionListener] }, _eventsCount: 2, _maxListeners: undefined, _connections: 0, _handle: TCP { reading: false, onconnection: [Function: onconnection], [Symbol(owner)]: [Circular] }, _usingWorkers: false, _workers: [], _unref: false, allowHalfOpen: true, pauseOnConnect: false, httpAllowHalfOpen: false, timeout: 120000, keepAliveTimeout: 5000, maxHeadersCount: null, headersTimeout: 40000, _connectionKey: '6::::8080', [Symbol(IncomingMessage)]: [Function: IncomingMessage], [Symbol(ServerResponse)]: [Function: ServerResponse], [Symbol(kCapture)]: false, [Symbol(asyncId)]: 79 }

The code above then works like that: