> For the complete documentation index, see [llms.txt](https://servercraft.coolstone.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://servercraft.coolstone.dev/node.js.md).

# Node.js

Servercraft can also be used programmatically through Node.js. To get started, install the package.

```bash
npm i servercraft
```

## Initialize

```js
const servercraft = require('servercraft')
const server = new servercraft()
```

## Setup

```js
server.setup(startAfter, args, config, version)
```

If `startAfter` is false, you can omit or pass `null` for the `args` and `config` parameters. If `startAfter` is true, you can omit the `config` parameter.

## Start

```js
server.start(args, config)
```

## Stop

```js
server.stop()
```

## Get IP

```js
server.ip
```

Args are command-line arguments, and config is a JSON object. You can find a list of all the arguments [here](/args.md). You can find a list of all the config options below.

## Download

Servercraft also allows you to only download a JAR file to a directory.

```javascript
require('servercraft').download('version', 'target dir')
```

## Config

| Parameter           | About                                                                                       | Type   |
| ------------------- | ------------------------------------------------------------------------------------------- | ------ |
| maxMemoryAllocation | maxMemoryAllocation is the maximum amount of memory that the server can use. This is in MB. | Number |
| minMemoryAllocation | minMemoryAllocation is the minimum amount of memory that the server can use. This is in MB. | Number |

### Start

{% hint style="info" %}
`config` is optional
{% endhint %}

```javascript
servercraft.start('args', { maxMemoryAllocation:"1024M", minMemoryAllocation:"1024M" )
```

### Setup

```javascript
servercraft.setup(startAfter,'args',config)
```

<table><thead><tr><th>Parameter</th><th>About</th><th>Type</th><th data-type="checkbox">Required</th></tr></thead><tbody><tr><td>startAfter</td><td>Start server after setup</td><td>bool</td><td>true</td></tr><tr><td>args</td><td>If startAfter is true, pass these command-line arguments to <code>start()</code></td><td>string</td><td>false</td></tr><tr><td>config</td><td>If startAfter is true, pass this to <code>start()</code></td><td>object</td><td>false</td></tr></tbody></table>

### Delete your server

```javascript
servercraft.delete()
```

### Get path to the directory&#x20;

```javascript
servercraft.dirpath
```
