Setting up your local development environment with MessageBird

⏱ 10 min read

In this MessageBird Developer Tutorial you’ll first learn how to get started with MessageBird by setting up first your local development environment.

MessageBird provides an SDK (Software Development Kit) for Node.js. This helper library facilitates interactions between your Node.js application's code and the MessageBird API, so you don’t have to craft raw REST API requests. Along this tutorial we’ll explain how to get started with MessageBird in Node.js.

Install Node.js and NPM

Make sure that you have Node.js version 0.10 at least—as this is the minimum version of that the SDK requires. You also need npm, a package manager for Node. The two are typically installed in a single bundle; we recommend you to always use the latest versions of both Node.js and npm.

To verify which version do you have, open a terminal and run the following two commands:

node -v
npm -v

In both cases, your terminal should return a version number, for example:

$ node -v
v9.4.0
$ npm -v
6.1.0

If you don’t get a version number but something like

node: command not found
instead, you need to install Node.js and npm first. We’ll explain you how.

MAC

Go to the Node.js Downloads page and choose the macOS Installer. The installer is a standard Mac package file with a UI that guides you through the installation process. If you prefer, it’s also possible to install Node.js through a package manager, such as Homebrew.

LINUX

Installation through a package manager is the easiest option. The Node.js package manager downloads page contains instructions for most Linux distributions.

WINDOWS

Go to the Node.js Downloads page and choose the Windows Installer. The installer is a Windows executable installer (MSI) with a UI that guides you through the installation process.

Updating npm

As mentioned above, the Node.js installer is a bundle that includes npm. The package manager, however, receives more frequent updates and the version included in the Node.js installer may not the latest one. Don’t worry, you can update npm independently by going to a terminal and issuing the following command:

npm install npm@latest -g

If you receive a permission error, try again and prefix the command with

sudo
.

Installing the MessageBird SDK

You use npm to install the MessageBird SDK for Node.js. The SDK is open source, and you can browse the code in this GitHub repository; it’s also listed on npmjs.com so that npm knows where to find it. SDKs and other libraries are always installed for each project as a dependency and stored in a project-specific directory called

node_modules
that npm manages.

Each Node.js project that uses npm needs a

package.json
file that includes information both about the current package (your project, such as name and version), as well as the list of dependencies that it relies on (such as the MessageBird SDK).

Create a new project directory or open an existing project directory in your terminal.

For a new project that doesn't have a

package.json
file yet, just run the following command and follow the instructions on screen:

npm init

Once you have a

package.json
file, you have two options for adding the MessageBird SDK to it:

Using the install command

Type the following command:

npm install messagebird

This command installs the latest version of the SDK and automatically updates the files

package.json
and
package-lock.json
.

Editing package.json

Create a new

package.json
file or, if you already have this file, add the SDK to it. A minimal file that only defines the MessageBird SDK as a dependency should look like this:

{
"dependencies": {
"messagebird": "^2.1.4"
}
}

Keep in mind that you have to specify the version of the SDK in the file. You can see the available SDK versions on npmjs.com and learn more about different ways to specify versions, for example with ranges, in the documentation of npm's semver module.

After saving the file, open a terminal in the directory into which you’ve stored it and type this command:

npm install

This command installs everything specified in your package file.

Nice work! 🎉

Your Node.js development environment and project directory are ready now!

Start building!

Let's head over to the next MessageBird Developer Tutorials and learn how to send your first SMS using Node.JS.

Want to get started but not quite sure how? Feel free to let us know at support@messagebird.com; we'd love to help.

Cookie Settings