Africa’s Talking Node.js(express) Application for sending SMS

James Chege
4 min readMar 31, 2019

Develop an sms app using Node.js(express)

Code for the app developed here can be found in this Github repository:

Setup an account at Africa’s Talking.

Africa’s Talking is a unified API platform for software developers in Africa building SMS, USSD, Voice, Payments and Airtime applications.

Visit and create a new account or login if you have one.

Your dashboard should look as shown in the image below after email confirmation.

Click “Go To Sandbox App button. You will be redirected to a page that looks as shown in the image below.

Setup and Lauch simulator

In this case you will not be able to use your phone to receive messages. Instead, you will use sandbox simulator which is freely provided by Africa’s Talking. You can access the sandbox simulator via a link in your dashboard. see picture below.

A picture of showing a link to launch the simulator

After clicking the link to launch simulator you’ll se a page which will prompt you to add a phone number. In our case we’ll use +254720000111. So, go ahead and add the number. Picture below shows how the page looks like.

After launching the simulator, you’ll be able to dial USSD codes and receive messages.

Sending SMS

At the end of this section(“SMS”) you will be able to learn how to send an sms using the Africa’s Talking API.

How the SMS service works

When we send an SMS the sent sms will appear in the outbox folder as shown in the image below.

A picture showing the view of sent messages

The last thing that we’ll do for the setup is generate an api Key which we are going to use to send requests. The api key can be generate under the settings menu as shown below.

We are now ready to start writing the code:

  1. Create a file named .env in the root of your project and add the api Key there. Also add a username. For testing purposes we are going to use sandbox as our username. Use ‘sandbox’ for development in the test environment.

2. Initialise a node application via yarn init or npm init

3. Install express, dotenv, nodemon, body-parser and africastalking dependencies via yarn add express africastalking dotenv nodemon body-parseror npm install express africastalking dotenv nodemon body-parser -— save

4. In the root directory (current directory) of the app, create a file named index.js and add the following code into the file.

5. Create another file in the root of your project and name it app.js and add the following code into the file.

6. Modify your package.json file to include a script to run the app. The file should then look something like below.

7. In your your root folder via the terminal type yarn start or npm start to start the app.

8. Visit postman client and send a POST request like shown below.

Note that we are using the phone number(+254720000111) which we used to setup our simulator with.

9. Visit your Africa’s Talking dashboard and you should be able to see the sent message under the outbox folder as shown below

The the message will be displayed in our simulator as shown below.

Whoops! We are done! The Code for the app developed is available here: