# Hello Anon World I

Welcome to our **npm** tutorial series, walking you through using **Anyone** with **Javascript**. We'll walk you through starting the Anyone client, routing your first request through and some cool features built into the SDK! Let's get started.

{% hint style="info" %}
**Installing NPM Package**

This tutorial assumes you have already installed npm and the anyone-client package (either globally or in your local development folder). If you haven't, check out [install](https://docs.anyone.io/sdk/npm/install "mention")
{% endhint %}

## Setting Up Your Environment

For this tutorial, we will be using[ Visual Studio Code](https://code.visualstudio.com/) to view and edit code, but you can choose any IDE. Create a new directory for this tutorial, in our case `sdk-test.`

We will be running our code as a node module, which can be instantiated using npm. In addition to your IDE, you will need a terminal window open in the same directory (this can also be done from within VS Code).&#x20;

From your terminal, run&#x20;

```
npm init es6 --save  
```

This will setup your project directory as an npm module, creating a `package.json` file and configuring it as a module. Next, from your IDE, create a local file to run your code. In our case, this is `hello.js.`

<div data-full-width="true"><figure><img src="https://content.gitbook.com/content/AA9P3lN6X0LnMGWCOpyt/blobs/0Gv5FkqOWfnmeTl26Nx0/Screenshot%202024-10-23%20at%2000.10.16.png" alt="" width="318"><figcaption><p>Creating file hello.js within the project directory</p></figcaption></figure></div>

## Importing and Starting Anon

We will be importing **anon**, the underlying software binary for Anyone, into our newly created `hello.js` file:

```javascript
import { Anon } from "@anyone-protocol/anyone-client";
```

The simplest way to start the anon binary is to create a new *instance* of the imported library, and calling its first function `.start()`&#x20;

<pre class="language-javascript"><code class="lang-javascript"><strong>import { Anon } from "@anyone-protocol/anyone-client";
</strong>
const anon = new Anon();
anon.start();
</code></pre>

To run your program, return to your terminal, and run `node` followed by your program name:

{% code title="Your Terminal" fullWidth="false" %}

```
node hello.js
```

{% endcode %}

This starts the client, which will automatically negotiate a circuit within the Anyone Network! You can see this happen in real time. Once the client has started, it won't shut off automatically - it will continue to run until stopped.&#x20;

<figure><img src="https://content.gitbook.com/content/AA9P3lN6X0LnMGWCOpyt/blobs/xd2TPjJuiFqpzXeFZ2tl/Screenshot%202024-10-23%20at%2000.31.50.png" alt="" width="563"><figcaption></figcaption></figure>

To terminate, type `Ctrl-C` or `Cmd-C` into the terminal window depending on your OS. You've now created your first circuit from code!

<details>

<summary>I get an error!</summary>

Make sure that you have npm and anyone-client installed. Check out [install](https://docs.anyone.io/sdk/npm/install "mention")

</details>

## Starting and Stopping&#x20;

Let's make our code a little more robust, and give ourselves the ability to stop the client.&#x20;

The anon binary should be called from **asynchronous** functions to ensure the client can continue to run without blocking the rest of your application, and called within a **try-catch** block so that network issues can be handled gracefully. We will structure a simple asynchronous function **main** and run the same code.&#x20;

```javascript
import { Anon } from "@anyone-protocol/anyone-client";

async function main() {
    const anon = new Anon();
    try {
        await anon.start();    
    } catch(error) {
        console.log(error)
    }
}

main()
```

We now introduce our second client function `.stop()` - for now, let's stop the client 15 seconds after the circuit is created.

Lets put an **await** statement before the start function so the program waits for it to complete before stopping (though currently, this resolves immediately), add a 15 second wait, and put the stop function within the **finally** clause of the try-catch block (so that it runs regardless of any issues). In the future, we can replace this 15 second wait with some real commands!&#x20;

```javascript
    try {
        await anon.start();
        await new Promise(resolve => setTimeout(resolve, 15000));
    } catch(error) {
        console.log(error)
    } finally {
        await anon.stop()
    }
```

Check out the full source on [GitHub](https://github.com/anyone-protocol).&#x20;

And that's a wrap! You have now successfully started and stopped **anon** from JavaScript code! If you're ready to explore the range of functions available yourself, head straight to the API reference at [library](https://docs.anyone.io/sdk/npm/library "mention"). If not, let's start making some requests over the internet!

{% content-ref url="ii" %}
[ii](https://docs.anyone.io/sdk/npm/tutorials/ii)
{% endcontent-ref %}
