let eventRecords = [ { subject: "We've received your Cox Mobile order", event_qualifier: 'SalesforceOrderId', notification_file_name: 'bd2f6ec8-e751-4377-a06b-d22b9c4802a9.json', customer_type: 'RESI', loggingIndex: [ '801030000029wDeAAI' ], account_id12: '476245807101', time_zone: 'GMT-0800', notification_category: 'General', event_type_class: 'All_EN', time_stamp_at_source: '1676390565325', global_transaction_id: 'e858aaa6-e384-42ca-95a5-212ad20a4ce8', generic_config: `{"globalConfig":{"excludeHNEvents":"Event87,Event88,Event89,Event90,Event91,Event92,Event100,Event205,Event206,Event207,Event208,Event209,Event234,Event244,Event245,Event247,Event168,Event169,Event170,Event171","whitelist":["[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"],"threeci_config":{"trigger_id":"157233","sms_generic_path":"/api/send_message.php","sms_workflow_path":"/api/workflow-initiator.php"},"Blacklist":["[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]"],"BlackOutStartTime":"21:00","BlackOutEndTime":"14:30","storedProcedureDetails":{"SP_SELECTACCOUNTSERVICES_DETAILS":{"databaseName":"xSTAGE","schemaName":"CNS_APP","procedureName":"SP_SELECTACCOUNTSERVICES","catalogName":"XXCO_CNS_COMMON"}},"HNflagCheckServiceCode":"'27755'","cbEvents":["Event397","Event401","Event300","Event322","Event393","Event394","Event302","Event307","Event308","Event309","Event47","Event120","Event121","Event122","Event94","Event95","Event96","Event97","Event98","Event182","Event267","Event270","Event199","Event178","Event184","Event187","Event188","Event192","Event168","Event169","Event170","Event171","Event221","Event154","Event190","Event191","Event205","Event206","Event207","Event208","Event209","Event220","Event234","Event244","Event245","Event247","Event257","Event61","Event87","Event88","Event90","Event93","Event157","Event185","Event233","Event243","Event210","Event235","Event85","Event159","Event194","Event254","Event101","Event102","Event103","Event200","Event99","Event149","Event202","Event256","Event123","Event124","Event287","Event108","Event213","Event203","Event201","Event137","Event53","Event107","Event91","Event92","Event297","Event289","Event259","Event260","Event261","Event262","Event349","Event350","Event339","Event340","Event324","Event362","Event370","Event304","Event305","Event374","Event375","Event271","Event328","Event391","Event396","Event346","Event347"],"cbResiEvents":["Event63","Event8","Event193","Event253","Event1","Event214","Event215","Event216","Event217","Event12","Event324","Event13","Event14","Event17","Event18","Event29","Event296","Event144","Event316"],"SMSMethodology":{"corePreferredMTN":{"smsAddressPath":["Customer.Details.preferredMTN"],"applicablePath":"All"},"mobilePreferredMTN":{"smsAddressPath":["Customer.Details.primaryLineMTN"],"applicablePath":"All"},"mobileLineMTN":{"smsAddressPath":["Request.Header.communicationProtocolValue","Request.ExtAttrs[?(@.key == 'mobileNumber')].value"],"applicablePath":"All"},"coreAllMTN":{"smsAddressPath":["Customer.Details.ICOMSPhoneNumberList"],"applicablePath":"All"},"coreAnyMTN":{"smsAddressPath":["Customer.Details.ICOMSPhoneNumberList[0]","Customer.Details.ICOMSPhoneNumberList[1]","Customer.Details.ICOMSPhoneNumberList[2]"],"applicablePath":"All"},"mobileAllMTN":{"smsAddressPath":["Request.Header.communicationProtocolValue","Request.ExtAttrs[?(@.key == 'mobileNumber')].value","Customer.Details.MobileNumberList"],"applicablePath":"AllPath"},"mobilePreferredAndLineMTN":{"smsAddressPath":["Request.Header.communicationProtocolValue","Request.ExtAttrs[?(@.key == 'mobileNumber')].value","Customer.Details.primaryLineMTN"],"applicablePath":"AllPath"},"coreAllAndmobilePreferredMTN":{"smsAddressPath":["Customer.Details.ICOMSPhoneNumberList","Customer.Details.primaryLineMTN"],"applicablePath":"AllPath"},"AllMTN":{"smsAddressPath":["Customer.Details.preferredMTN","Customer.Details.ICOMSPhoneNumberList","Request.Header.communicationProtocolValue","Request.ExtAttrs[?(@.key == 'mobileNumber')].value","Customer.Details.MobileNumberList"],"applicablePath":"AllPath"},"CBPreferredMTN":{"smsAddressPath":["Request.ExtAttrs[?(@.key == 'phoneNumber')].value"],"applicablePath":"AllPath"},"CBSourceMTN":{"smsAddressPath":["Request.Header.communicationProtocolValue"],"applicablePath":"AllPath"},"ResiSourceMTN":{"smsAddressPath":["Request.Header.communicationProtocolValue"],"applicablePath":"AllPath"}}}}`, bounce_flag: 'false', last_updated_timestamp: '1676390565325', message_id: '3c44c1ce-ae50-4216-89e3-bc4dda3367ac', transaction_id: 'bd2f6ec8-e751-4377-a06b-d22b9c4802a9', notification_type: 'OUTBOUND', open_flag: 'false', msg_status: 'COMPLETED', display_event: 'MobileOrderReceipt', payload: { isbackordercancel: false, firstname: 'Johnosn', financedetails: [Array], icomsemailaddress: '[email protected]', services: 'Mobile', list: [Array], billtypecode: 'S', lastname: 'George', hasamountfinanced: false, isfinanced: false, addressline3: 'BOULDER CITY, NV 89005-3407', orderdetails: [Array], addressline2: '5899 Test tds account AV', addressline1: 'APT 50', customername: 'Johnosn George', isbackorder: false }, template_name: 'All_MobileOrderReceipt_All_EN.hbs', event_type: 'MobileOrderReceipt', source_qualifier: 'Source43', requested_time: 1676390564922, icoms_pref_category: 'General', communication_channel: 'EG_EM', account_id9: '245807101', event_name: 'MobileOrderReceipt', ttl_timestamp: 1678982565, config: { eventMode: 'realtime', displayName: 'MobileOrderReceipt', is_workflow_api: 'false', eventRules: [Object], description: 'MobileOrderReceipt', sns_delivery_topic_name: 'cns-sns-deliver-notifications', auditFlag: 'true', icomsPreferenceCategory: 'General', enabledSites: 'All', template_bucket_name: 'cns-templates-qa', enabledBillTypeCode: [Array], adobeConfig: [Object], debugValueEmail: '[email protected];[email protected]', notification_bucket_name: 'cns-payloads-qa', displayCategory: 'General', eventIdQualifier: 'SalesforceOrderId', parsePayload: 'N', debugValuePhone: '4702421603', defaultEventType: 'MobileOrderReceipt', mailBoxFromName: 'Cox Communications', duplicate: [Object], parsePayloadField: 'ErrorDetails', eventEnabled: 'true', transaction_bucket_name: 'cns-s3-config-qa', timeToLiveInMilliSeconds: '300000', debugFlag: 'N', files_bucket_name: 'cns-s3-files-qa', eventCommunications: [Array], subjectDynamic: 'N' }, source_name: 'Source43', sequence_number: '2416952629641304222464', communication_value: '[email protected]', blackout: { startTime: '21:00', timezone: 'America/Los_Angeles', endTime: '07:30' }, ucc_classification: 'Quote and Order Confirmation', event_id: '801030000029wDeAAI', event_number: 'Event331', customer: { Preferences: [Object], Details: [Object] }, site_code: 'LAS', site_id: '476' }, { ttl_timestamp: 1678982572, account_id12: '476245807101', status_description: 'Error: Invalid Type/State/Status/Channel is received in the request for EventNumber - Event317, AccountId12 - 476245807101, EventId - 68f2fc7c-127c-4903-8de5-b563960bc52a', time_stamp_at_source: '1676390572560', global_transaction_id: '8a00c9e8-612f-4be1-bdf7-fd533da45d83', last_updated_timestamp: '1676390572561', transaction_id: 'db3d8f40-f964-456d-a9be-688a8f8fbcbb', source_name: 'Source41', msg_status: 'DISCARDED', payload: { canceldate: 'February 14,2023', channel: 'WEB_RESIDENTIAL', ordernumber: '00043379', state: 'PROCESSING', type: 'ORDER', orderdate: 'February 14,2023', operation: 'CREATE', status: 'PASSED_VELOCITY', notificationname: '' }, communication_value: 'Unknown', communication_channel: 'EG_EM', event_id: '68f2fc7c-127c-4903-8de5-b563960bc52a', event_number: 'Event317', account_id9: '245807101', site_id: '476', event_name: 'FraudDetection' }, { ttl_timestamp: 1678982943, account_id12: '476245807101', status_description: 'Error: Invalid Type/State/Status/Channel is received in the request for EventNumber - Event317, AccountId12 - 476245807101, EventId - 21cc37b3-16ee-498e-8da9-20f40370c5bb', time_stamp_at_source: '1676390943020', global_transaction_id: '7140ee09-5891-4d09-8bab-b61e3ce42856', last_updated_timestamp: '1676390943020', transaction_id: '59090f51-525e-4507-869f-ae3792083b5e', source_name: 'Source41', msg_status: 'DISCARDED', payload: { canceldate: 'February 14,2023', channel: 'WEB_RESIDENTIAL', ordernumber: '00043379', state: 'COMPLETED', type: 'ORDER', orderdate: 'February 14,2023', operation: 'UPDATE', status: 'PASSED', notificationname: '' }, communication_value: 'Unknown', communication_channel: 'EG_EM', event_id: '21cc37b3-16ee-498e-8da9-20f40370c5bb', event_number: 'Event317', account_id9: '245807101', site_id: '476', event_name: 'FraudDetection' }, ] // let [ records ] = records let records = [] let totalRecordsFile = "" eventRecords.forEach((element) => { // console.log(element) // totalRecordsFile = `${totalRecordsFile}\n${JSON.stringify( // element // )}`; records.push(JSON.stringify(element)) }); console.log(records.join("\n"))
Write, Run & Share NodeJS code online using OneCompiler's NodeJS online compiler for free. It's one of the robust, feature-rich online compilers for NodeJS language,running on the latest LTS version NodeJS 16.14.2. Getting started with the OneCompiler's NodeJS editor is easy and fast. The editor shows sample boilerplate code when you choose language as NodeJS and start coding. You can provide the dependencies in package.json
.
Node.js is a free and open-source server environment. Node.js is very popular in recent times and a large number of companies like Microsoft, Paypal, Uber, Yahoo, General Electric and many others are using Node.js.
Google chrome's javascript engine V8
and is pretty fast.Asynchronous
, event-driven
and works on single-thread model
thus eliminating the dis-advantages of multi-thread model.Express is one of the most popular web application framework in the NodeJS echosystem.
let moment = require('moment');
console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));
const _ = require("lodash");
let colors = ['blue', 'green', 'yellow', 'red'];
let firstElement = _.first(colors);
let lastElement = _.last(colors);
console.log(`First element: ${firstElement}`);
console.log(`Last element: ${lastElement}`);
Following are the libraries supported by OneCompiler's NodeJS compiler.