|
| 1 | +# Dapr with Node.js 12 & TypeScript |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +*Develop Dapr applications using Node.js 12 and TypeScript. Includes Dapr, Node.js, eslint, yarn, and the TypeScript compiler.* |
| 6 | + |
| 7 | +| Metadata | Value | |
| 8 | +|----------|-------| |
| 9 | +| *Contributors* | The Visual Studio Container Tools team | |
| 10 | +| *Definition type* | Docker Compose | |
| 11 | +| *Languages, platforms* | Node.js, TypeScript, Dapr | |
| 12 | + |
| 13 | +## Dapr Notes |
| 14 | + |
| 15 | +When the dev container is created, the definition automatically initializes Dapr on a separate Docker network (to isolate it from Dapr instances running locally or in another Dapr dev container). This is done via the `postCreateCommand` in the `.devcontainer/devcontainer.json` and the `DAPR_NETWORK` environment variable in the `.devcontainer/docker-compose.yml`. The `DAPR_REDIS_HOST` and `DAPR_PLACEMENT_HOST` environment variables ensure that Dapr `run` commands implicitly connect to the Dapr instance in that Docker network. |
| 16 | + |
| 17 | +## Using this definition with an existing folder |
| 18 | + |
| 19 | +This definition installs `tslint` globally and includes the VS Code TSLint extension for backwards compatibility, but [TSLint has been deprecated](https://github.com/palantir/tslint/issues/4534) in favor of ESLint, so `eslint` and its corresponding extension has been included as well. |
| 20 | + |
| 21 | +Both `eslint`and `typescript` are installed globally for convenance, but [as of ESLint 6](https://eslint.org/docs/user-guide/migrating-to-6.0.0#-plugins-and-shareable-configs-are-no-longer-affected-by-eslints-location), you will need to install the following packages locally to lint TypeScript code: `@typescript-eslint/eslint-plugin`, `@typescript-eslint/parser`, `eslint`, `typescript`. |
| 22 | + |
| 23 | +To get started, follow these steps: |
| 24 | + |
| 25 | +1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine. |
| 26 | + |
| 27 | +2. To use VS Code's copy of this definition: |
| 28 | + 1. Start VS Code and open your project folder. |
| 29 | + 2. Press <kbd>F1</kbd> select and **Remote-Containers: Add Development Container Configuration Files...** from the command palette. |
| 30 | + 3. Select the Dapr with Node.js 12 & TypeScript definition. |
| 31 | + |
| 32 | +3. To use latest-and-greatest copy of this definition from the repository: |
| 33 | + 1. Clone this repository. |
| 34 | + 2. Copy the contents of `containers/dapr-typescript-node-12/.devcontainer` to the root of your project folder. |
| 35 | + 3. Start VS Code and open your project folder. |
| 36 | + |
| 37 | +4. After following step 2 or 3, the contents of the `.devcontainer` folder in your project can be adapted to meet your needs. |
| 38 | + |
| 39 | +5. Finally, press <kbd>F1</kbd> and run **Remote-Containers: Reopen Folder in Container** to start using the definition. |
| 40 | + |
| 41 | +## Testing the definition |
| 42 | + |
| 43 | +This definition includes some test code that will help you verify it is working as expected on your system. Follow these steps: |
| 44 | + |
| 45 | +1. If this is your first time using a development container, please follow the [getting started steps](https://aka.ms/vscode-remote/containers/getting-started) to set up your machine. |
| 46 | +2. Clone this repository. |
| 47 | +3. Start VS Code, press <kbd>F1</kbd>, and select **Remote-Containers: Open Folder in Container...** |
| 48 | +4. Select the `containers/dapr-typescript-node-12` folder. |
| 49 | +5. After the folder has opened in the container, press <kbd>F5</kbd> to start the project. This will automatically run `npm install` and compile the source before starting it. |
| 50 | +6. Start the application with Dapr: |
| 51 | + |
| 52 | + ```bash |
| 53 | + $ cd test-project |
| 54 | + $ npm run dapr |
| 55 | + ``` |
| 56 | + |
| 57 | +7. In a separate terminal, invoke the application via Dapr: |
| 58 | + |
| 59 | + ```bash |
| 60 | + # Deposit funds to the account (creating the account if not exists) |
| 61 | + $ curl -d 42 -H "Content-Type: application/json" -w "\n" -X POST http://localhost:3500/v1.0/invoke/test/method/accounts/123/deposit |
| 62 | + 42 |
| 63 | + # Withdraws funds from the account |
| 64 | + $ curl -d 10 -H "Content-Type: application/json" -w "\n" -X POST http://localhost:3500/v1.0/invoke/test/method/accounts/123/withdraw |
| 65 | + 32 |
| 66 | + # Get the balance of the account |
| 67 | + $ curl -w "\n" http://localhost:3500/v1.0/invoke/test/method/accounts/123 |
| 68 | + 32 |
| 69 | + $ |
| 70 | + ``` |
| 71 | + |
| 72 | +## License |
| 73 | + |
| 74 | +Copyright (c) Microsoft Corporation. All rights reserved. |
| 75 | + |
| 76 | +Licensed under the MIT License. See [LICENSE](https://github.com/Microsoft/vscode-dev-containers/blob/master/LICENSE). |
0 commit comments