Open with one click!
In [1]:
1+1
2
In [2]:
process.version
'v10.19.0'
In [3]:
function test(x, y) { s = [] for (var i = 0; i < x; i++) { s.push(y + i) } return s }
In [4]:
test(10, 23)
[ 23, 24, 25, 26, 27, 28, 29, 30, 31, 32 ]
In [5]:
const fs = require("fs")
In [6]:
$$.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" ] }
In [7]:
async function a() { console.log("start") await new Promise((done, fail) => setTimeout(done, 1000)); console.log("done") }
In [8]:
$$.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

In [9]:
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, onread: null, 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] super_: { [Function: Readable] ReadableState: [Function: ReadableState], super_: [Function], _fromList: [Function: fromList], from: [Function] } }, [Symbol(ServerResponse)]: { [Function: ServerResponse] super_: { [Function: OutgoingMessage] super_: [Function] } }, [Symbol(asyncId)]: 63 }

The code above then works like that:

In [ ]: