SJCNet

SJCNet is the home of architect/developer/techie, Simon Coope.

Amazon Alexa Skills: Post 2 - Set-up your development environment

This post is a continuation of a series of posts describing how to create a custom skill for the Alexa Voice System (AVS). The posts in this series are:

1. Overview and prerequisites.
2. How to set-up your development environment (this post).
3. How to develop a custom skill.
4. How to test your skill on an Alexa-enabled device.
5. How to successfully certify your skill.

All the source code for this project can be found on Github.

Overview

To develop an Alexa skill locally we'll need to set-up our environment with Node, and use Node Package Manager (NPM) to pull down the required packages. Then we're going to set-up the Alexa App Server package to allow us to run and test our skills locally.

Steps

The following steps detail what you need to do to set-up your local development environment to be able to locally develop an Alexa custom skill.

Node & NVM

Before we can start we need to ensure we have node installed, and not just the latest version (oh no). We need to make sure we use the version of Node that's supported by Lambda (check here for current support).

Depending on the OS you're running, you will need to find instructions to install Node Version Manager (NVM). I'm running Windows and I used this version.

When done if you run nvm list you should see the following (where I’ve got v0.10.36 in use):

NVM List

Project Setup

Next I'm going to create a folder in my local code directory (i.e. C:\Code\SJCNet.Alexa.Skills.WhoIsRight).

In this folder I'm going to create a src and test folder. Then run npm init to generate a package.json file. Please note, when asked about the test command use "mocha".

Once that's all be done, you'll need to install the required NPM modules. We'll be installing the following modules:

  • alexa-app - Encapsulates some of the Alexa api instructions for us. (NPM Link).
  • mocha - A JavaScript test framework for node.js and the browser. (NPM Link).
  • chai - A BDD/TDD assertion library for node.js that can be paired with Mocha. (NPM Link).

I'm installing the packages using the following commands.

npm install alexa-app --save
npm install mocha chai --save-dev

Install Alexa App Server

The Alexa App Server is a web server module for Alexa skills using Node.JS and Express. Using this we can run and test our skills locally.

To install this package create another folder (e.g. C:\Code\alexa-app-server) and use GIT to clone the Github Repo. For example:

git clone https://github.com/matt-kruse/alexa-app-server.git
```
Once the repo has been pulled locally, open a command prompt and move into the *alexa-app-folder*.  Then run `npm install` to pull down any package dependencies.

Next move into the *alexa-app-server/examples* folder and run `node server` to start the express server.

In the console output you should see the sample apps load (with their respective URLs) and you'll see the port the app server is running on.  

Next you can test the *helloworld* skill by going to the following URL (depends on the port your app server opened on):

*http://localhost:8080/alexa/helloworld*

Here you can test the skill by changing the request type and run the *NameIntent* to generate Alexa output in the response (shown below).

**Request**
![AppServerRequest](/content/images/2016/11/AppServerRequest-1.png)

**Response**
![AppServerResponse](/content/images/2016/11/AppServerResponse.png)

If you want to test against the local app server, you need to leave the command prompt open.

Now we're ready to move onto the [next post](https://www.sjcnet.co.uk/2016/12/03/amazon-alexa-skills-post-3-create-a-custom-skill/) and start creating our custom skill intents. 


Author image
About Simon Coope
Sydney, Australia Website
Experienced developer/consultant. Loves all things development, technology, gadgets, football and running.