Skip to content

Commit 58519e4

Browse files
authored
Nim: Add info about compiling to JS and running. (#2682)
* Nim: Add info about compiling to JS and running. * Revert README.md.
1 parent dec8876 commit 58519e4

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

nim/content.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,22 @@ $ docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app %%IMAGE%% nim c -r main
1818

1919
## Compile to JavaScript
2020

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

2323
```console
24-
$ docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app %%IMAGE%% nim js -r main.nim
24+
$ docker run --rm -v "$PWD":/usr/src/app -w /usr/src/app %%IMAGE%% nim js main.nim
25+
```
26+
27+
To compile and run, use a multi-stage Dockerfile with Node.js:
28+
29+
```dockerfile
30+
FROM %%IMAGE%% AS builder
31+
COPY . .
32+
RUN nim js -o:app.js src/app.nim
33+
34+
FROM node:latest
35+
COPY --from=builder /usr/src/app/app.js .
36+
CMD ["node", "app.js"]
2537
```
2638

2739
## Managing packages with Nimble

0 commit comments

Comments
 (0)