@Kognise/

Repl.it API Example

Nodejs

An example on using my repl.it-api Node package.

fork
loading
Files
  • index.js
  • package-lock.json

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.16763913172207112","path":"index.js","file":{"path":"index.js","content":{"asEncoding":{"base64":"Y29uc3QgUmVwbGl0Q2xpZW50ID0gcmVxdWlyZSgncmVwbC5pdC1hcGknKQpjb25zdCBjbGllbnQgPSBuZXcgUmVwbGl0Q2xpZW50KCkKCmNsaWVudC5jcmVhdGUoKS50aGVuKCgpID0+IHsKICBjb25zb2xlLmxvZygnQ3JlYXRlZCcpCiAgcmV0dXJuIGNsaWVudC5jb25uZWN0KCkKfSkudGhlbigoKSA9PiB7CiAgY29uc29sZS5sb2coJ0Nvbm5lY3RlZCcpCiAgcmV0dXJuIGNsaWVudC53cml0ZU1haW4oJ3JlcXVpcmUoXCdleHByZXNzXCcpKCkubGlzdGVuKCknKQp9KS50aGVuKCgpID0+IHsKICBjb25zb2xlLmxvZygnV3JvdGUnKQogIHJldHVybiBjbGllbnQucnVuKHsKICAgIG91dHB1dDogKG91dHB1dCkgPT4gY29uc29sZS5sb2coJ091dHB1dDonLCBvdXRwdXQudHJpbSgpKSwKICAgIHRpbWVkT3V0OiAoKSA9PiBjb25zb2xlLmxvZygnVGltZWQgb3V0IScpLAogICAgaW5zdGFsbFN0YXJ0OiAoKSA9PiBjb25zb2xlLmxvZygnSW5zdGFsbCBzdGFydCcpLAogICAgaW5zdGFsbE91dHB1dDogKG91dHB1dCkgPT4gY29uc29sZS5sb2coJ0luc3RhbGwgb3V0cHV0OicsIG91dHB1dC50cmltKCkpLAogICAgaW5zdGFsbEVuZDogKCkgPT4gY29uc29sZS5sb2coJ0luc3RhbGwgZW5kJyksCiAgICBsaXN0ZW46IChwb3J0KSA9PiBjb25zb2xlLmxvZygnTGlzdGVuaW5nIG9uIHBvcnQnLCBwb3J0KQogIH0pCn0pLnRoZW4oKHJlc3VsdCkgPT4gewogIGNvbnNvbGUubG9nKCdSZXN1bHQ6JywgcmVzdWx0KQogIHJldHVybiBjbGllbnQuY2xvc2UoKQp9KS50aGVuKCgpID0+IHsKICBjb25zb2xlLmxvZyhjbGllbnQuZ2V0SW5mbygpKQp9KQ=="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const ReplitClient = require('repl.it-api')
const client = new ReplitClient()

client.create().then(() => {
  console.log('Created')
  return client.connect()
}).then(() => {
  console.log('Connected')
  return client.writeMain('require(\'express\')().listen()')
}).then(() => {
  console.log('Wrote')
  return client.run({
    output: (output) => console.log('Output:', output.trim()),
    timedOut: () => console.log('Timed out!'),
    installStart: () => console.log('Install start'),
    installOutput: (output) => console.log('Install output:', output.trim()),
    installEnd: () => console.log('Install end'),
    listen: (port) => console.log('Listening on port', port)
  })
}).then((result) => {
  console.log('Result:', result)
  return client.close()
}).then(() => {
  console.log(client.getInfo())
})
node v10.16.0