{"id":15170698,"url":"https://github.com/smerth/node-js-projects","last_synced_at":"2026-02-14T00:02:49.264Z","repository":{"id":147044665,"uuid":"68231928","full_name":"smerth/node-js-projects","owner":"smerth","description":"Simple node demos","archived":false,"fork":false,"pushed_at":"2016-09-19T20:36:01.000Z","size":386,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-14T15:18:42.060Z","etag":null,"topics":["cheeriojs","express-js","httpster","mochajs","node-js","socket-io","websocket"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smerth.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-14T18:24:10.000Z","updated_at":"2022-06-17T02:25:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"0db054a7-4310-4b08-9aad-6f4fabf18452","html_url":"https://github.com/smerth/node-js-projects","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"3baa02d434bb36fa6b73cf3277d9e5de94adc0d2"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/smerth/node-js-projects","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smerth%2Fnode-js-projects","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smerth%2Fnode-js-projects/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smerth%2Fnode-js-projects/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smerth%2Fnode-js-projects/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smerth","download_url":"https://codeload.github.com/smerth/node-js-projects/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smerth%2Fnode-js-projects/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275062953,"owners_count":25398887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-14T02:00:10.474Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cheeriojs","express-js","httpster","mochajs","node-js","socket-io","websocket"],"created_at":"2024-09-27T08:21:40.243Z","updated_at":"2026-02-14T00:02:44.236Z","avatar_url":"https://github.com/smerth.png","language":"JavaScript","readme":"# Node.js Essential Training\n\n\n\n\u003e These notes accompany my builds of the projects from [Node.js Essential Training](https://www.lynda.com/Node-js-tutorials/Node-js-Essential-Training/417077-2.html) on Lynda.com.  My repo for these projects can be found [here]().\n\n## node_js_http_module\n\nThis folder contains projects to illustrate the basic functionality of Node.js built in http module.\n\n### make_a_request\n\nTo run the server\n\n```bash\nnode request.js\n```\n\nExecutes\n\n```javascript\nvar https = require(\"https\");\nvar fs = require(\"fs\");\n\nvar options = {\n\thostname: \"en.wikipedia.org\",\n\tport: 443,\n\tpath: \"/wiki/George_Washington\",\n\tmethod: \"GET\"\n};\n\nvar req = https.request(options, function(res) {\n\n\tvar responseBody = \"\";\n\n\tconsole.log(\"Response from server started.\");\n\tconsole.log(`Server Status: ${res.statusCode} `);\n\tconsole.log(\"Response Headers: %j\", res.headers);\n\n\tres.setEncoding(\"UTF-8\");\n\n\tres.once(\"data\", function(chunk) {\n\t\tconsole.log(chunk);\n\t});\n\n\tres.on(\"data\", function(chunk) {\n\t\tconsole.log(`--chunk-- ${chunk.length}`);\n\t\tresponseBody += chunk;\n\t});\n\n\tres.on(\"end\", function() {\n\t\tfs.writeFile(\"george-washington.html\", responseBody, function(err) {\n\t\t\tif (err) {\n\t\t\t\tthrow err;\n\t\t\t}\n\t\t\tconsole.log(\"File Downloaded\");\n\t\t});\n\t});\n\n});\n\nreq.on(\"error\", function(err) {\n\tconsole.log(`problem with request: ${err.message}`);\n});\n\nreq.end();\n\n\n```\n\n\n\n### simple_server\n\nTo run the server\n\n```bash\nnode server.js\n```\n\nserver.js\n\n```javascript\nvar http = require(\"http\");\n\nvar server = http.createServer(function(req, res) {\n\n\tres.writeHead(200, {\"Content-Type\": \"text/html\"});\n\n\tres.end(`\n\t\t\u003c!DOCTYPE html\u003e\n\t\t\u003chtml\u003e\n\t\t\t\u003chead\u003e\n\t\t\t\t\u003ctitle\u003eHTML Response\u003c/title\u003e\n\t\t\t\u003c/head\u003e\n\t\t\t\u003cbody\u003e\n\t\t\t\t\u003ch1\u003eServing HTML Text\u003c/h1\u003e\n\t\t\t\t\u003cp\u003e${req.url}\u003c/p\u003e\n\t\t\t\t\u003cp\u003e${req.method}\u003c/p\u003e\n\t\t\t\u003c/body\u003e\n\t\t\u003c/html\u003e\n\t`);\n\n});\n\nserver.listen(3000);\n\nconsole.log(\"Server listening on port 3000\");\n```\n\nThe page is served and two variables available to the node.js are printed to the screen.\n\n```javascript\n\u003cp\u003e${req.url}\u003c/p\u003e\n\u003cp\u003e${req.method}\u003c/p\u003e\n```\n\n\n\n### simple_file_server\n\nTo run the server\n\n```bash\nnode fileserver.js\n```\n\na simple fileserver\n\n```javascript\nvar http = require(\"http\");\nvar fs = require(\"fs\");\nvar path = require(\"path\");\n\nhttp.createServer(function(req, res) {\n\n\tconsole.log(`${req.method} request for ${req.url}`);\n\n\tif (req.url === \"/\") {\n\t\tfs.readFile(\"./public/index.html\", \"UTF-8\", function(err, html) {\n\t\t\tres.writeHead(200, {\"Content-Type\": \"text/html\"});\n\t\t\tres.end(html);\n\t\t});\n\n\t} else if (req.url.match(/.css$/)) {\n\n\t\tvar cssPath = path.join(__dirname, 'public', req.url);\n\t\tvar fileStream = fs.createReadStream(cssPath, \"UTF-8\");\n\n\t\tres.writeHead(200, {\"Content-Type\": \"text/css\"});\n\n\t\tfileStream.pipe(res);\n\n\t} else if (req.url.match(/.jpg$/)) {\n\n\t\tvar imgPath = path.join(__dirname, 'public', req.url);\n\t\tvar imgStream = fs.createReadStream(imgPath);\n\n\t\tres.writeHead(200, {\"Content-Type\": \"image/jpeg\"});\n\n\t\timgStream.pipe(res);\n\n\t} else {\n\t\tres.writeHead(404, {\"Content-Type\": \"text/plain\"});\n\t\tres.end(\"404 File Not Found\");\n\t}\n\n}).listen(3000);\n\n\nconsole.log(\"File server running on port 3000\");\n\n```\n\n\n\n### simple_json_server\n\nTo run the server\n\n```bash\nnode api.js\n```\n\nA simple json api\n\n```javascript\nvar http = require(\"http\");\n\nvar data = require(\"./data/inventory\");\n\nhttp.createServer(function(req, res) {\n\n\tif (req.url === \"/\") {\n\t\tres.writeHead(200, {\"Content-Type\": \"text/json\"});\n\t    res.end(JSON.stringify(data));\n\t} else if (req.url === \"/instock\") {\n\t\tlistInStock(res);\n\t} else if (req.url === \"/onorder\") {\n\t\tlistOnBackOrder(res);\n\t} else {\n\t\tres.writeHead(404, {\"Content-Type\": \"text/plain\"});\n\t\tres.end(\"Whoops... Data not found\");\n\t}\n\n\t\n\n}).listen(3000);\n\nconsole.log(\"Server listening on port 3000\");\n\n\nfunction listInStock(res) {\n\n\tvar inStock = data.filter(function(item) {\n\t\treturn item.avail === \"In stock\";\n\t});\n\n\tres.end(JSON.stringify(inStock));\n\n}\n\nfunction listOnBackOrder(res) {\n\n\tvar onOrder = data.filter(function(item) {\n\t\treturn item.avail === \"On back order\";\n\t});\n\n\tres.end(JSON.stringify(onOrder));\n\n}\n```\n\n\n\n### collect_POST_data\n\nTo run the server\n\n```bash\nnode formserver.js\n```\n\nHandle a POST request\n\n```javascript\nvar http = require(\"http\");\nvar fs = require(\"fs\");\n\nhttp.createServer(function(req, res) {\n\n\tif (req.method === \"GET\") {\n\t\tres.writeHead(200, {\"Content-Type\": \"text/html\"});\n\t    fs.createReadStream(\"./public/form.html\", \"UTF-8\").pipe(res);\n\t} else if (req.method === \"POST\") {\n\n\t\tvar body = \"\";\n\n\t\treq.on(\"data\", function(chunk) {\n\t\t\tbody += chunk;\n\t\t});\n\n\t\treq.on(\"end\", function() {\n\n\t\t\tres.writeHead(200, {\"Content-Type\": \"text/html\"});\n\n\t\t\tres.end(`\n\n\t\t\t\t\u003c!DOCTYPE html\u003e\n\t\t\t\t\u003chtml\u003e\n\t\t\t\t\t\u003chead\u003e\n\t\t\t\t\t\t\u003ctitle\u003eForm Results\u003c/title\u003e\n\t\t\t\t\t\u003c/head\u003e\n\t\t\t\t\t\u003cbody\u003e\n\t\t\t\t\t\t\u003ch1\u003eYour Form Results\u003c/h1\u003e\n\t\t\t\t\t\t\u003cp\u003e${body}\u003c/p\u003e\n\t\t\t\t\t\u003c/body\u003e\n\t\t\t\t\u003c/html\u003e\n\n\t\t\t`);\n\n\n\t\t});\n\n\n\t}\n\n\n}).listen(3000);\n\nconsole.log(\"Form server listening on port 3000\");\n```\n\n\n\n## httpster_file_server\n\nHttpster is a web server that will serve static content.\n\nInstall Httpster\n\n```bash\nnpm install - g httpster\n```\n\nRun httpster and give it a port flag and give it a directory to serve.\n\n```bash\nhttpster -p 8080 -d ./public\n```\n\n\n\n#### Running node modules: global vs local\n\nTry this:\n\nRun\n\n```bash\nwhich httpster\n```\n\nreturns\n\n```bash\n/usr/local/bin/httpster\n```\n\nThis is where the httpster executable files is located when it is installed globally. When a node module is installed globally the executable file is linked automatically so that terminal is aware of its location.  So to run the executable you can simply call it by name.\n\n```bash\nhttpster -p 8080 -d ./public\n```\n\n\n\nNow, remove httpster global install.\n\n```bash\nnpm remove -g httpster\n```\n\nNow install it locally\n\n```bash\nnpm install httpster\n```\n\nThis creates a node_modules folder with httpster installed there.  \n\nTry to run httpster\n\n```bash\nhttpster -p 8080 -d ./public\n```\n\nThe httpster executable cannot be found.\n\n```bash\n-bash: /usr/local/bin/httpster: No such file or directory\n```\n\nTo run it you need to specify the executable's location.  \n\n```bash\n./node_modules/httpster/bin/httpster -p 8080 -d ./public\n```\n\nThis applies to all node modules\n\n## express_js_term_dictionary\n\n### Install\n\n```bash\nnpm install\n```\n\n### Start the app server\n\n```bash\nnode app\n```\n\nThe app server serves your application files from the public folder on port 3000.\n\n### Start the app server with node-dev\n\n```bash\nnode-dev app.js\n```\n\nnode-dev will reload the express server any time you make changes to app-server.js. (N.B. - it doesn't restart the browser, just the server.)\n\nThe app server serves your application files from the public folder on port 3000.\n\nSee the readme file in the app folder...\n\n## websockets_messaging_app\n\nSee project folder for detailed readme...\n\n## sockets_io_messaging_app\n\nSee project folder for detailed readme...\n\n\n\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmerth%2Fnode-js-projects","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmerth%2Fnode-js-projects","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmerth%2Fnode-js-projects/lists"}