NodeRun is the newest Profound Logic product dedicated to making it easier for Node.js developers to create applications by moving development to a cloud-based environment. NodeRun comes with a full IDE with Visual Designer, editor, debugger, and Node.js already pre-installed. Some of NodeRun's most notable capabilities include design screens, the ability to develop and run application within the program, full debugging capabilities, the ability to install NPM packages, manage your own Node.js server, work with active sessions to see end-user activity, host database and built-in Database Explorer, a command-line terminal for full control of your space, as well as the ability to share and collaborate with other developers.
Getting started with NodeRun is quick and easy. All you need is a modern internet browser (Google Chrome, Mozilla Firefox, etc.) and that's it. Every NodeRun Space is free to build and comes with its own files, database, and server. To get started visit NodeRun.com create an account and begin developing, it's that easy!
This 8 part blog series will give you a set of exercises to help you build a Node.js applications that work with employee data. Last week we discussed how to Consume a Web Service, and this week, we will show you how to use NPM to be able to email your employee list application.
Exercise 10 - Using NPM to Email Employee List
In this exercise, you will write code to email a list of employees to yourself. In the toolbar under the Your App section, click the Server drop-down and click the Install NPM Packages button. Next, add the name'gmail-send' to the Install NPM Packages window and press 'Ok.'
Alternatively, use the Terminal feature and type: NPM install gmail-send.
What is NPM?
- www.npmjs.com hosts a repository of reusable Node.js packages
- There are many packages for almost every imaginable purpose
- Packages will often use other packages
- For example, nodemailer is a popular package for sending emails
- gmail-send is a package that implements nodemailer but simplifies usage specifically for sending emails from a gmail account
Create Node.js Script Named email.js
In the toolbar press the New drop-down menu and select JavaScript File.
Once you open a new JavaScript File, write the code that is below:
After you write out the above code, save this JavaScript File as email.js.
Code Explained
- require() is a Node.js API that loads files or loads installed npm packages
require('gmail-send')
loads the gmail-send packagerequire('./credentials.json')
loads gmail account credentials from a json file
Test the Email Functionality
In your toolbar press the Launch drop-down menu and select Launch App in Browser button. Next, press the Email Employee List (NPM) button.
Please note:
- Don't click the option more than once! The menu will remain on screen after the email is sent.
- Check your inbox to see if you received the employee list.
You are all done! Thanks for trying out this lab!
As a next step, try to think of creative ways to enhance the screens or the functionality behind the screens you built.
Please leave any questions or comments you might have for us here.
If you missed out on any of our previous Guided Labs here is a recap of those exercises:
- Guided Lab: Employee Data Application Part 1 showed you how to build your employee lookup application from scratch.
- Guided Lab: Employee Data Application Part 2 showed you how to use the database-driven auto-complete option and how to add a dynamic image to your display.
- Guided Lab: Employee Data Application Part 3 showed you how to create an employee listing application with a grid of your employee's records.
- Guided Lab: Employee Data Application Part 4 showed you how to enhance an employee records grid and how to add the capability to review record data within that grid.
- Guided Lab: Employee Data Application Part 5 showed you how to list a web service within NodeRun.
- Guided Lab: Employee Data Application Part 6 showed you how to create details web service within NodeRun.
- Guided Lab: Employee Data Application Part 7 showed you how to Consume a Web Service.