# Scripting

## Plugin Walkthrough - 'hello-exchange' script.js

So to get started with the *hello-exchange* server script, first we are going to need to make the actual script that will be run:

1. Create a new file called `script.js`, in the same directory as the `config.json` (`plugins/src/plugins/hello-exchange/server/script.js`)
2. Fill this `script.js` with the code found in the box below.

<details>

<summary><em>hello-plugin</em>  <code>script.js</code> code</summary>

{% code lineNumbers="true" %}

```javascript
'use strict';

const { publicMeta, meta } = this.configValues;
const {
	app,
	loggerPlugin,
	toolsLib
} = this.pluginLibraries;
const helloWorld = require('hello-world-npm');
const moment = require('moment');

const init = async () => {
	loggerPlugin.info(
		'HELLO-PLUGIN PLUGIN initializing...'
	);

	if (!meta.private_message.value) {
		throw new Error('Configuration value private required');
	}
};

init()
	.then(() => {
		app.get('/plugins/hello-plugin/info', (req, res) => {
			loggerPlugin.verbose(
				req.uuid,
				'GET /plugins/hello-plugin/info'
			);

			return res.json({
				public_message: publicMeta.public_message.value,
				private_message: meta.private_message.value,
				library_message: helloWorld(),
				moment_timestamp: moment().toISOString(),
				exchange_info: toolsLib.getKitConfig().info
			});
		});
	})
	.catch((err) => {
		loggerPlugin.error(
			'HELLO-PLUGIN PLUGIN error during initialization',
			err.message
		);
	});
```

{% endcode %}

</details>

Check the screenshot below to compare and make sure you have the file in the correct location.&#x20;

<figure><img src="https://3965312054-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP899VqAdyGFgLTy9SY%2Fuploads%2FYNIMPcFF5ThENQgdQjlK%2Fimage.png?alt=media&#x26;token=b0549787-378e-4850-bad1-42dbfac89f2b" alt=""><figcaption></figcaption></figure>

## Calling the End Point

Now we have constructed '*hello-plugin*', let's call the endpoint. First, we will need to build the plugin.

1. If the terminals from earlier (when following how to set up dev mode) are no longer up, lets first get them going.&#x20;
   1. In one terminal navigate to *hollaex-kit/server* and run `docker-compose up`
   2. In the other,  enter the docker container with:  `docker exec -it server_hollaex-kit-server_1 /bin/bash`
2. With both the containers running build the plugin by running: `node plugins/dev.js --plugin=hello-plugin` inside the container (terminal we ran 'docker exec...' in)

Great news! This is all we had to do, and can now have a look at the plugin in the browser through the following URL:

<http://localhost:10013/plugins/hello-plugin/info>

You should see an output similar to below:

<figure><img src="https://3965312054-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP899VqAdyGFgLTy9SY%2Fuploads%2FG6mf9tKGQjlmVUL2gysv%2Fimage.png?alt=media&#x26;token=9a19d872-ef77-48f6-906f-c799f6116796" alt=""><figcaption><p>Chrome</p></figcaption></figure>

<figure><img src="https://3965312054-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MP899VqAdyGFgLTy9SY%2Fuploads%2FuRjJHd3HdqC5OUoTZVR9%2Fimage.png?alt=media&#x26;token=351c586c-2e38-4885-a9cd-ab2ee83ade1f" alt=""><figcaption><p>Firefox</p></figcaption></figure>
