REPL
flecks provides @flecks/repl
to make it easy to run a
REPL inside your running
application. @flecks/repl
provides a command to easily connect to your application.
Prerequisites
In order to use it you will need to have socat.
Play with a REPL
Let's create an application to test the REPL:
- npm
npm init @flecks/app repl-test
- npm
npx flecks add -d @flecks/repl
Start your application:
- npm
npm run start
It will just sit there. Open another terminal in the project directory and run the command:
- npm
npx flecks repl
You will be greeted with a prompt:
repl-test>
That's our application ID! We can run commands:
repl-test> flecks.get('@flecks/core')
{ id: 'repl-test' }
Confirm we're actually in our application by killing it:
repl-test> process.exit(0)
That will kick us back out to the terminal. If we try to run the command again, we'll get an error that looks something like this:
[...] socat[...] E connect(5, AF=1 "/tmp/flecks/repl-test/repl/repl-test-[...].sock", 57): Connection refused
This is because there's no application to connect to anymore.
Extend the REPL
Your flecks can implement @flecks/repl.commands and/or @flecks/repl.context to add context or commands to the REPL.
For instance, @flecks/passport-local
implements a command to easily create a user account in
the REPL.