{ "key_pair_value_system": true, "answer_rating_count": "", "question_feedback_html": { "html_star": "", "html_star_feedback": "" }, "answer_average_rating_value": "", "answer_date_js": "2024-09-01T20:23:41-04:00", "answer_date": "2024-09-01 20:23:41", "is_docs_available": "", "is_excel_available": "", "is_pdf_available": "", "count_file_available": 0, "main_page": "student_question_view", "question_id": "8880393", "url": "\/study-help\/questions\/please-help-installed-the-moment-module-already-but-i-do-8880393", "question_creation_date_js": "2024-09-01T20:23:41-04:00", "question_creation_date": "Sep 01, 2024 08:23 PM", "meta_title": "[Solved] Please HELP!! Installed the moment module | SolutionInn", "meta_description": "Answer of - Please HELP!! Installed the moment module already but I do not know how to log the feedback comments on a separate fil | SolutionInn", "meta_keywords": "help,installed,moment,module,log,feedback,comments,separate,file,add,timestamp,one", "question_title_h1": "Please HELP!! Installed the moment module already but I do not know how to log the feedback comments on a separate file and how to", "question_title": "Please HELP!! Installed the moment module already but I do not know", "question_title_for_js_snippet": "Please HELP Installed the moment module already but I do not know how to log the feedback comments on a separate file and how to add a timestamp to each one Your job is to use NPM to download a free module called moment described in our textbook and use Node js built in fs module to log the customer feedback messages to a text file named feedback log Each feedback has to be logged on its own line and has to be started with a time stamp in a pair of square brackets See the following screenshot for the exact format app js This is a simple web site that hosts a fake Wake Tech Credit Union web site It is used to demonstrate how easy it is to create and deploy a web sever using Node js var express require('express') var fs require('fs') var moment require(' node modules moment') app js Define the sample application var SampleApp function () Scope var self this Helper functions Set up server IP address and port using env variables defaults self setupVariables function () Set the environment variables we need self ipaddress process env IP self port process env PORT 5000 if (typeof self ipaddress undefined ) self ipaddress 127 0 0 1 Populate the cache self populateCache function () if ( typeof self zcache undefined ) self zcache 'index html' '' Local cache for static content self zcache 'index html' fs readFileSync(' index html') Retrieve entry (content) from cache param string key Key identifying content to retrieve from cache self cache get function (key) return self zcache key terminator the termination handler Terminate server on receipt of the specified signal param string sig Signal to terminate on self terminator function (sig) if ( typeof sig string ) console log(' s Received s terminating sample app ', Date(Date now()), sig) process exit(1) console log(' s Node server stopped ', Date(Date now()) ) Setup termination handlers (for exit and a list of signals) self setupTerminationHandlers function () Process on exit and signals process on('exit', function () self terminator() ) Removed 'SIGPIPE' from the list bugz 852598 'SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM' forEach( function (element, index, array) process on(element, function () self terminator(element) ) ) App server functions (main app logic here) Create the routing table entries handlers for the application self createRoutes function () self routes self routes ' feedback' function (req, res) console log( Received a customer feedback req body feedback ) res send( WTCU Feedback setTimeout(function() window location href ' ' ,3000) Thanks for your feedback ) self routes ' ' function (req, res) res setHeader('Content Type', 'text html') res send(self cache get('index html') ) Initialize the server (express) and create the routes and register the handlers self initializeServer function () self createRoutes() self app express createServer() self app express() self app set('port', process env PORT 3333) self app set('ip', process env IP 127 0 0 1 ) self app use(express static( dirname)) self app use(express bodyParser()) self app use(express json()) self app use(express urlencoded()) Add handlers for the app (from the routes) for ( var r in self routes) self app get(r, self routes r ) maps the HTTP GET request self app post(r, self routes r ) maps the HTTP POST request Initializes the sample application self initialize function () self setupVariables() self populateCache() self setupTerminationHandlers() Create the express server and routes self initializeServer() Start the server (starts up the sample application) self start function () Start the app on the specific interface (and port) self app listen(self app get('port'), function () console log(' s Node server started on s d ', Date(Date now() ), self app get('ip'), self app get('port')) ) Sample Application main() Main code var zapp new SampleApp() zapp initialize() zapp start() ", "question_description": "

Please HELP!! Installed the moment module already but I do not know how to log the feedback comments on a separate file and how to add a timestamp to each one. <\/p>

<\/p>

Your job is to use NPM to download a free module called moment<\/strong> described in our textbook and use Node.js built-in fs<\/strong> module to log the customer feedback messages to a text file named feedback.log<\/strong>. Each feedback has to be logged on its own line and has to be started with a time stamp in a pair of square brackets. See the following screenshot for the exact format:<\/p>

\/** <\/em>app.js <\/em>This is a simple web site that hosts <\/em>a fake Wake Tech Credit Union web site. <\/em>It is used to demonstrate how easy it is to <\/em>create and deploy a web sever using Node.js. <\/em>*\/ <\/em> var <\/strong>express = require('express'); var <\/strong>fs = require('fs'); var <\/strong>moment = require('.\/node_modules\/moment'); app.js \/** <\/em> * Define the sample application. <\/em> *\/ <\/em>var <\/strong>SampleApp = function<\/strong>() { \/\/ Scope. var <\/strong>self = this<\/strong>; \/* ================================================================ *\/ \/* Helper functions. *\/ \/* ================================================================ *\/ \/** <\/em> * Set up server IP address and port # using env variables\/defaults. <\/em> *\/ <\/em> <\/em>self.setupVariables = function<\/strong>() { \/\/ Set the environment variables we need. \/\/self.ipaddress = process.env.IP; \/\/self.port = process.env.PORT || 5000; \/\/if (typeof self.ipaddress === \"undefined\") { \/\/ self.ipaddress = \"127.0.0.1\"; \/\/}; }; \/** <\/em> * Populate the cache. <\/em> *\/ <\/em> <\/em>self.populateCache = function<\/strong>() { if <\/strong>(typeof <\/strong>self.zcache === \"undefined\") { self.zcache = { 'index.html': '' }; } \/\/ Local cache for static content. self.zcache['index.html'] = fs.readFileSync('.\/index.html'); }; \/** <\/em> * Retrieve entry (content) from cache. <\/em> * <\/em>@param <\/em>{string} key Key identifying content to retrieve from cache. <\/em> *\/ <\/em> <\/em>self.cache_get = function<\/strong>(key) { return <\/strong>self.zcache[key]; }; \/** <\/em> * terminator === the termination handler <\/em> * Terminate server on receipt of the specified signal. <\/em> * <\/em>@param <\/em>{string} sig Signal to terminate on. <\/em> *\/ <\/em> <\/em>self.terminator = function<\/strong>(sig){ if <\/strong>(typeof <\/strong>sig === \"string\") { console.log('%s: Received %s - terminating sample app ...', Date(Date.now()), sig); process.exit(1); } console.log('%s: Node server stopped.', Date(Date.now()) ); }; \/** <\/em> * Setup termination handlers (for exit and a list of signals). <\/em> *\/ <\/em> <\/em>self.setupTerminationHandlers = function<\/strong>(){ \/\/ Process on exit and signals. process.on('exit', function<\/strong>() { self.terminator(); }); \/\/ Removed 'SIGPIPE' from the list - bugz 852598. ['SIGHUP', 'SIGINT', 'SIGQUIT', 'SIGILL', 'SIGTRAP', 'SIGABRT', 'SIGBUS', 'SIGFPE', 'SIGUSR1', 'SIGSEGV', 'SIGUSR2', 'SIGTERM' ].forEach(function<\/strong>(element, index, array) { process.on(element, function<\/strong>() { self.terminator(element); }); }); }; \/* ================================================================ *\/ \/* App server functions (main app logic here). *\/ \/* ================================================================ *\/ \/** <\/em> * Create the routing table entries + handlers for the application. <\/em> *\/ <\/em> <\/em>self.createRoutes = function<\/strong>() { self.routes = { }; self.routes['\/feedback'] = function<\/strong>(req, res) { console.log(\"-- Received a customer feedback: [\" + req.body.feedback + \"]\"); res.send(\"WTCU Feedback<\/title><script>setTimeout(function(){window.location.href='\/'},3000);<\/script><\/head><body>Thanks for your feedback!<\/body><\/html>\"); }; self.routes['\/'] = <strong>function<\/strong>(req, res) { res.setHeader('Content-Type', 'text\/html'); res.send(self.cache_get('index.html') ); }; }; <em>\/** <\/em><em> * Initialize the server (express) and create the routes and register <\/em><em> * the handlers. <\/em><em> *\/ <\/em><em> <\/em>self.initializeServer = <strong>function<\/strong>() { self.createRoutes(); \/\/self.app = express.createServer(); self.app = express(); self.app.set('port', process.env.PORT || 3333); self.app.set('ip', process.env.IP || \"127.0.0.1\"); self.app.use(express.static(__dirname)); \/\/self.app.use(express.bodyParser()); self.app.use(express.json()); self.app.use(express.urlencoded()); \/\/ Add handlers for the app (from the routes). <strong>for <\/strong>(<strong>var <\/strong>r <strong>in <\/strong>self.routes) { self.app.get(r, self.routes[r]); \/\/ maps the HTTP GET request self.app.post(r, self.routes[r]); \/\/ maps the HTTP POST request } }; <em>\/** <\/em><em> * Initializes the sample application. <\/em><em> *\/ <\/em><em> <\/em>self.initialize = <strong>function<\/strong>() { self.setupVariables(); self.populateCache(); self.setupTerminationHandlers(); \/\/ Create the express server and routes. self.initializeServer(); }; <em>\/** <\/em><em> * Start the server (starts up the sample application). <\/em><em> *\/ <\/em><em> <\/em>self.start = <strong>function<\/strong>() { \/\/ Start the app on the specific interface (and port). self.app.listen(self.app.get('port'), <strong>function<\/strong>() { console.log('%s: Node server started on %s:%d ...', Date(Date.now() ), self.app.get('ip'), self.app.get('port')); }); }; }; \/* Sample Application. *\/ <em>\/** <\/em><em> * main(): Main code. <\/em><em> *\/ <\/em><strong>var <\/strong>zapp = <strong>new <\/strong>SampleApp(); zapp.initialize(); zapp.start();<\/pre> <p> <\/p> <p> <\/p>",
    "transcribed_text": "",
    "related_book": {
        "title": "Object Databases The Essentials",
        "isbn": "020156341X, 978-0201563412",
        "edition": "1st Edition",
        "authors": "Mary E. S. Loomis",
        "cover_image": "https:\/\/dsd5zvtm8ll6.cloudfront.net\/si.question.images\/book_images\/64ed95dae1cff_47869.jpg",
        "uri": "\/textbooks\/object-databases-the-essentials-1st-edition-9780201563412",
        "see_more_uri": "\/textbooks\/computer-science-yorick-2550"
    },
    "question_posted": "2024-09-01 20:23:41",
    "step_by_step_answer": "The Answer is in the image, click to view ...",
    "students_also_viewed": [
        {
            "url": "\/sketch-the-graphs-of-f-and-g-in-the-same-coordinate",
            "description": "Sketch the graphs of f and g in the same coordinate plane. (Include two full periods.) 1. f (x) = sin x g (x) = sin x\/3 2. f (x) = sin x g (x) = 4 sinx",
            "stars": 3.5
        },
        {
            "url": "\/study-help\/modern-mathematical-statistics-with-applications\/211-prove-eux2-2-dx-112-00-12-t-1987640",
            "description": "=+21.1. Prove ( e-ux2 \/2 dx =1-1\/2. ,00 12 T = 00",
            "stars": 3.5
        },
        {
            "url": "\/pooling-information-from-the-output-design-and-reviewing-their-progress",
            "description": "Pooling information from the output design and reviewing their progress, Chip and Anna proceed to the next stage, the design of input. Web pages must be designed to capture input information easily...",
            "stars": 3
        },
        {
            "url": "\/study-help\/questions\/please-show-all-work-for-every-step-ad-and-every-10014270",
            "description": "Please show all work for every step (A-D) and every question... Including the formulas that were used! 1). What is the annual real pre-tax Net returns in the third year? a). $12,374. b). $8,899. c)....",
            "stars": 3
        },
        {
            "url": "\/study-help\/questions\/wes-wants-to-eat-his-friends-to-some-are-games-2059777",
            "description": "Wes wants to eat his friends to some are games. He has 50 ame tokens. WE three responses show a number of friends We could divide his tokens among nly? 4 people 2 people 3 people CLEAR",
            "stars": 3
        },
        {
            "url": "\/study-help\/questions\/as-shown-in-fig-460-a-horizontal-beam-is-hinged-716564",
            "description": "As shown in Fig. 4.60, a horizontal beam is hinged to the wall at point A. The length of the beam is 1 = 2 m and it weighs W = 150 N. Point C is the center of gravity of the beam and it is...",
            "stars": 3
        },
        {
            "url": "\/study-help\/questions\/gl0202-algo-based-on-exercise-213-prepare-journal-entries-1644809",
            "description": "GL0202 (Algo) - Based on Exercise 2-13 Prepare journal entries for each transaction and identify the financial statement impact of each entry. The financial statements are automatically generated...",
            "stars": 3
        },
        {
            "url": "\/study-help\/questions\/create-a-function-bookendlist-that-consumes-a-list-of-integers-716943",
            "description": "Create a function bookend_list that consumes a list of integers as a parameter and returns the first and last elements as a new list. If the original list is empty, return an empty list instead. Unit...",
            "stars": 3
        },
        {
            "url": "\/study-help\/questions\/rst-inc-2018-statement-of-comprehensive-income-net-sales-cost-5542144",
            "description": "RST, Inc. 2018 Statement of comprehensive income Net sales Cost of goods sold Depreciation Earnings before interest and taxes Interest paid Taxable income Taxes Net income Dividends paid Addition to...",
            "stars": 3
        },
        {
            "url": "\/study-help\/questions\/the-equity-section-of-benton-corporations-statement-of-financial-position-5709766",
            "description": "The equity section of Benton Corporation's statement of financial position as of December 31, 2018 is as follows: Equity Share capital-ordinary 5 par value; authorized, 2,000,000 shares; issued,...",
            "stars": 3
        },
        {
            "url": "\/study-help\/intercultural-communication\/3-explain-the-relationship-between-history-power-and-intercultural-communication-2116637",
            "description": "3. Explain the relationship between history, power, and intercultural communication.",
            "stars": 3
        },
        {
            "url": "\/study-help\/intercultural-communication\/8-explain-the-contact-hypothesis-2116642",
            "description": "8. Explain the contact hypothesis.",
            "stars": 3
        },
        {
            "url": "\/study-help\/intercultural-communication\/7-identify-four-antecedents-that-influence-intercultural-contact-2116641",
            "description": "7. Identify four antecedents that influence intercultural contact.",
            "stars": 3
        }
    ],
    "next_back_navigation": {
        "previous": "\/study-help\/questions\/jan-1-traded-in-old-office-equipment-with-book-value-8880392",
        "next": "\/study-help\/questions\/please-help-me-thabk-you-required-information-the-following-information-8880394"
    },
    "breadcrumbs": [
        {
            "name": "Study help",
            "link": "https:\/\/www.solutioninn.com\/study-help\/questions-and-answers"
        },
        {
            "name": "Computer Science",
            "link": "https:\/\/www.solutioninn.com\/study-help\/questions-and-answers\/computer-science"
        },
        {
            "name": "Databases",
            "link": "https:\/\/www.solutioninn.com\/study-help\/questions\/computer-science-databases"
        },
        {
            "name": "Please HELP!! Installed the moment module already but I do not know",
            "link": "https:\/\/www.solutioninn.com\/study-help\/questions\/please-help-installed-the-moment-module-already-but-i-do-8880393"
        }
    ],
    "skill_details": {
        "skill_id": "656",
        "skill_name": "Databases",
        "parent_id": "8"
    }
}