NGINX Modern Apps > Class 3 - NGINX Dataplane Scripting Source | Edit on
Hello World [http/hello]¶
As is customary for any programming class, our first lab outputs “Hello World!” When acting as a web server, NGINX serves static content from files stored on disk. By using the js_content directive NGINX can serve dynamic content generated by JavaScript code. In this example, our code simply returns the string “Hello World!” and sets the return code to 200.
Step 1: Copy and paste the following commands to start your NGINX container with this lab’s files:
Step 2: Now let’s use curl to test our NGINX server:
Code Snippets¶
Our JavaScript code is in two files so we need two js_import lines to load them into our NGINX configuration. Notice in the js_content directives how we use a namespace to identify in which file a JavaScript function is located.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
The Javascript code to generate “Hello World!”:
The utils.js file will be part of all of our labs. It has one function that displays the version of the njs module in use on this NGINX server.