Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions nim/content.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,22 @@ $ docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app %%IMAGE%% nim c -r main

## Compile to JavaScript

Nim can compile to JavaScript. This image includes Node.js to serve as the runtime:
Nim can compile to JavaScript:

```console
$ docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app %%IMAGE%% nim js -r main.nim
$ docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app %%IMAGE%% nim js main.nim
```

To compile and run, use a multi-stage Dockerfile with Node.js:

```dockerfile
FROM %%IMAGE%% AS builder
COPY . .
RUN nim js -o:app.js src/app.nim

FROM node:latest
COPY --from=builder /usr/src/app/app.js .

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this is encoding the implicit assumption of WORKDIR /usr/src/app in the nim image (which is fine, but something you should be aware of / be doing intentionally if you're going to do it, since it makes that value slightly "stickier" to document it this way)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, and I was somewhat conflicted with this line... Initially, there was WORKDIR /app in both the builder and the runner images, which does make things more explicit but also noisier.

I think that as an example that is intended to be modified for your needs (I mean, you probably don't have an app called app anyway, duh) this is fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me -- do you want to wait for your other PR to merge this, or merge this as-is since it's correct even without image changes?

I'd rather have that merged now as is.

CMD ["node", "app.js"]
```

## Managing packages with Nimble
Expand Down