Node.js is a runtime platform for executing JavaScript in an event-driven environment, making it practical to build network applications outside web browsers. JavaScript is the language; Node.js is the runtime, also commonly called node. section 4.3
A minimal Node.js setup supports AWS programming from the terminal:
- Install Node.js for your operating system, then verify it with node --version; the examples target Node.js 14. section 4.3
- Verify npm, the Node.js package manager, with npm --version. section 4.3
- Run a script with node script.js, or install project dependencies with npm install. section 4.3 section 12.3
Node.js is used with the AWS SDK for JavaScript to call AWS APIs from application code. The SDK handles authentication, retries, HTTPS communication, and XML or JSON serialization, while Node.js runs the surrounding scripts and applications. section 4.3
AWS applications built with Node.js
A Simple S3 Gallery uses Node.js and the AWS SDK to upload images to S3 and download them for display. Other examples use Node.js to add DynamoDB items or send URL-processing messages to an SQS queue. section 7.5 section 12.3 section 14.2.4
Listing 12.3 nodetodo: Using docopt in Node.js (index.js)
const fs = require('fs'); #1 const docopt = require('docopt'); #2 const moment = require('moment'); #3 const AWS = require('aws-sdk'); #4 const db = new AWS.DynamoDB({ region: 'us-east-1' }); const cli = fs.readFileSync('./cli.txt', {encoding: 'utf8'}); #5 const input = docopt.docopt(cli, { #6 version: '1.0', argv: process.argv.splice(2) }); #1 Loads the fs module to access the filesystem #2 Loads the docopt module to read input arguments #3 Loads the moment module to simplify temporal types in JavaScript #4 Loads the AWS SDK module #5 Reads the CLI description from the file cli.txt #6 Parses the arguments, and saves them to an input variable
The listing shows a Node.js CLI loading modules, configuring the AWS SDK, reading arguments, and preparing DynamoDB access. section 12.3



