This example project demonstrates how to send SMS notifications (for a mobile marketing campaign) using Node.js and Express.
Go to your dashboard on Twilio. Click on Twilio Numbers and choose a number to setup.
On the phone number page, enter https://<appname.com>/message
into the Messaging Request URL field.
Now your subscribers will be able to text your new Twilio number to 'Subscribe' to your Marketing Notifications line.
Congratulations!
To run this project on your computer, download or clone the source. You will also need to download and install:
Finally you will also need to sign up for a Twilio account if you don't have one already.
Navigate to the project directory in your terminal
npm install
This should install all of our project dependencies from npm into a local node_modules
folder.
Next, open config.js
at the root of the project and update it with values from your environment and your Twilio account. You can either export these values as system environment variables (this is the default setup), or you can replace these values with hard-coded strings (be careful you don't commit them to git!).
This sample application stores data in a MongoDB database using Mongoose.
You can download and run MongoDB yourself
- OS X
- Linux
- Windows
- You can also use a hosted service like compose.io
Our application will be looking for a fully qualified MongoDB connection string with a username and password embedded in it.
To launch the application, you can use node .
in the project's root directory. You might also consider using nodemon for this. It works just like the node command, but automatically restarts your application when you change any source code files.
npm install -g nodemon \
nodemon .
You will likely need to expose your local Node.js web application on the public Internet to work with Twilio. We recommend using ngrok to accomplish this. Use ngrok to expose a local port and get a publicly accessible URL you can use to accept incoming calls or texts to your Twilio numbers.
The following example would expose your local Node application running on port 3000 at http://chunky-danger-monkey.ngrok.com
(reserved subdomains are a paid feature of ngrok):
ngrok -subdomain=chunky-danger-monkey 3000
MIT
- No warranty expressed or implied. Software is as is. Diggity.
- MIT License
- Lovingly crafted by Twilio Developer Education.