From 07be566e8f133f9a6cce3332a38b6d01d942f5e1 Mon Sep 17 00:00:00 2001 From: Tyler Perkins Date: Sat, 20 Nov 2021 16:00:01 -0500 Subject: [PATCH] Update for 20-11-21 16:00 --- lang/Node.js.wiki | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/lang/Node.js.wiki b/lang/Node.js.wiki index c205193..92a64a0 100644 --- a/lang/Node.js.wiki +++ b/lang/Node.js.wiki @@ -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