---
description: Tutorial on how to setup NodeJS and packages using npm for the webserver
---

# Setting up NodeJS and required packages

## Installing NodeJS

Go to  [https://nodejs.org/en/download](https://nodejs.org/en/download) and download the right version of NodeJS for your system

Open the installer, accept the terms of service and press next until you see the install button. Press it and after some time you will se a message that NodeJS is successfully installed.

<figure><img src="https://1355723674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFK9KBgKtblLSGBcSkhh3%2Fuploads%2FLfckIsC7fCApfT7W4KLX%2F2023-04-15%2014_47_54-Setting%20up%20NodeJS%20-%20WEBHOOK%20SERVER%20-%20Vivaldi.png?alt=media&#x26;token=4b0eec22-32af-4146-a828-71792cc82e33" alt=""><figcaption><p>You should see this screen when the program has installed successfully </p></figcaption></figure>

To check that node is installed you can type `node` into your terminal and you should see a message that says `Welcome to Node.js vXX.X.X`

## Installing packages

NodeJS includes a package manager called NPM (Node Package Manager). We will use this to install the necessary packages for the webserver to run

First create a folder for the webserver to run in.&#x20;

Next navigate into the folder using your terminal or in windows you can open the folder `Ctrl + Right-Click` and select open terminal here.

Then you need to initialize your project by typing this into your console

```bash
npm init -y
```

<figure><img src="https://1355723674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFK9KBgKtblLSGBcSkhh3%2Fuploads%2FtJsxsqaUzhLrKz4X9OVU%2F2023-04-15%2015_23_46-get-client.js%20-%20server%20-%20Visual%20Studio%20Code.png?alt=media&#x26;token=fab484c2-8131-4c85-90e7-8a4c308ee715" alt=""><figcaption><p>You should see this when the command was successful</p></figcaption></figure>

Next install the necessary packages using this command

```shell
npm install pg express body-parser float-array-to-string dotenv
```

* [**Body parser:**](https://www.npmjs.com/package/body-parser)\
  This package makes it so we can take in JSON files sent the webhook from the things stack and use them to insert data into our database
* [**PG (postgres)**](https://www.npmjs.com/package/pg)**:**\
  This package makes it so we can connect and query a postgres database.
* [**Express:**](https://www.npmjs.com/package/express)\
  This package is the main web framework for the server.
* [**Dotenv:**\
  ](https://www.npmjs.com/package/dotenv)This package makes it so we can use a `.env` file or the main enviroment variables on the computer to store our database details in to make the server more secure.
* [**Float to array to string:** ](https://www.npmjs.com/package/float-array-to-string)[\
  This package is used to turn an array of hexadecimal numbers into a float value to be inserted into the database. It can also turn a float value into an array of hexadecimal numbers](#user-content-fn-1)[^1]

<figure><img src="https://1355723674-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FFK9KBgKtblLSGBcSkhh3%2Fuploads%2FiaK54W10qZTiWOtsMfBm%2F2023-04-15%2015_24_06-get-client.js%20-%20server%20-%20Visual%20Studio%20Code.png?alt=media&#x26;token=4594680b-f17b-45d3-8767-3b0e664f8114" alt=""><figcaption><p>You should see this when the command was successful</p></figcaption></figure>

&#x20;

[^1]: Not using this in the current version of the webserver but still useful for further functionality in the future&#x20;
