> For the complete documentation index, see [llms.txt](https://help.clickatell.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.clickatell.com/developers-api-reference/developers-archive/sdks/nodejs.md).

# NodeJS

The NodeJS library is compatible with our HTTP and REST messaging APIs to interact with the Clickatell SMS Gateway. The NodeJS library below allows you to send one-way and two-way SMS messages using Clickatell’s SMS Platform.

[View on Github](https://github.com/clickatell/clickatell-node)

Inside the *test.js* file is an example implementation of the REST and HTTP API. Simply use the Clickatell platform package and use one of the methods to send. Add the message you want to send, the number you’re sending to, and the API key.

| `var` `clickatell = require("clickatell-platform");` `//clickatell.sendMessageRest("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE");` `clickatell.sendMessageHttp("Hello testing message", ["27XXXXX-NUMBER"], "APIKEY-HERE");` |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |

&#x20;

**Run the code**

Simply create a file called *test.js* and add the code above. Trigger the sending by running “*node test.js*” in your terminal. Remember to add the number you are sending to and your API Key to be able to send successfully.

| `node test.js` |
| -------------- |

#### &#x20;

**Handling API callbacks**

Create a file called *server.js,* paste the code below into it, and save. It has an express post method pointing to [yourdomain.com/sms](http://yourdomain.com/sms) that you will use to send the callback posts to your platform API in order to read the callback information.

Run the code by typing “*node server.js.*” It will start to run on port 80. Make sure it’s working correctly by navigating to [yourdomain.com](http://yourdomain.com/).

| `node server.js"` |
| ----------------- |

| `const express = require('express')const bodyParser = require('body-parser')` `const app = express()` `const http = require('http')const port = 80` `const server = http.createServer(app)` `app.use(bodyParser.urlencoded({     // to support URL-encoded bodies  extended: true}));app.use( bodyParser.json() );       // to support JSON-encoded bodies` `app.use(express.json());       // to support JSON-encoded bodiesapp.use(express.urlencoded()); // to support URL-encoded bodies` `server.listen(port, (err) => {  if` `(err) {    return` `console.log('something bad happened', err)  }` ``console.log(`server is listening on ${port}`);`` `app.get('/', function` `(req, res) {        res.send('It's working')    })` `app.post('/sms', function (req, res) {        const body = req.body        console.log(body);` ``res.set('Content-Type', 'text/plain')        res.send(`You sent: ${body}`)    })`` `})` |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

&#x20;

Once you’ve sent an SMS, the following data will be returned in the callback:&#x20;

DELIVERED\_TO\_GATEWAY:

* *integrationName*
* *messageId*
* *requestId*
* *clientMessageId*
* *to*
* *from*
* *statusCode*
* *status*
* *statusDescription*
* *timestamp*

RECEIVED\_BY\_RECIPIENT:

* *integrationName*
* *messageId*
* *requestId*
* *clientMessageId*
* *to*
* *from*
* *statusCode*
* *status*
* *statusDescription*
* *timestamp*


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.clickatell.com/developers-api-reference/developers-archive/sdks/nodejs.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
