Update for 20-11-21 16:00

This commit is contained in:
Tyler Perkins 2021-11-20 16:00:01 -05:00
parent 54b7b0d118
commit 07be566e8f

View File

@ -17,7 +17,15 @@ is `node`.
All modules are included by using the `require('MODULE')` syntax
|
| Module | Use |
----------------
| HTTP | classes, methods, etc to make Node.js server |
| uitl | utility functions for developers |
| fs | filesystem |
| url | parse urls |
| query string | work with the query string |
| stream | handling streaming data |
| zlib | compression |
== Events ==
@ -82,6 +90,31 @@ readFile('./sample.txt', 'utf8', (err, txt) => {
console.log('this is called after the fact');
}}}
== URL ==
Node.js can help you parse URLs and resolve where they lead. The module is
build into node.js. The following example code would print the hostname,
filepath, and search string (as an object)
{{{
//import express and url
const express = require('express');
const url_lib = require('url');
//create objects
const app = express();
const url = 'http://www.clortox.com/posts/';
const parsed_url = url_lib.parse(url, true);
//express listener
app.get('/', async (request, response) =>{
response.send(parsed_url.path);
});
//listen
app.listen(process.env.PORT || 3000, () => console.log('Available on localhost:3000'));
}}}
== Packages ==
Node.js's package manager is npm. It can download packages for you to use in