// console.log("Hello, World!");
// module1.js
// require('./module2')
// console.log('Inside Module1')

// // module2.js
// require('./module1')
// console.log('Inside Module2')



// const fs = require('fs'); 
// const eventemitter require('events'); 
// const readfile = async filepath => {
//   try { 
//     const data = await fs.promises.readfile(filepath, 'utf8'); 
//     return data; 
     
//   }  catch(err) { 
// console.log(err); } 
  
// } 
// class readevents extends eventemitter ( async execute(asyncfunc, ...args) { 15 16 17 this.emit ('begin'); try { const data = await asyncfunc(...args); this.emit('data', data); this.emit('end'); 18 19 20 21 22 23 24 25 } } 26) 28 27 const readevents = new readevents(); console.log('an error occurred');▷ this.emit ('error', err); } catch(err) { 29 readevents.on('begin', () => console.log('about to execute')); 30 readevents.on('end', () => console.log('done with execute')); 31 readevents.on('data', (data) => console.log('data:', data)); 32 33 readevents.execute(readfile, './data.txt');


// import express from 'express'; 
// import fs from 'fs'; 
// const app = express();
// const fspromises = fs.promises; 
// app.get('/download', (req, res, next) => {
//   fspromises.readfile('./file-not-exists.txt')
//   .then(data => res.send(data)) })
//   .catch(err => next(err));
//   }) 
  
//   app.use((err, req, res, next) => { 
    
//     console.log('error middleware - one'); 
//     next(err); 
//     }); 
    
//     bapp.use((err, req, res, next) => { 
//       console.log('error middleware - two'); 
//       res.status(500); 
//       }); 
    
//     res.send('internal server error'); 
//     app.use((err, req, res, next) => { 5 26 }); console.log('error middleware - three'); 57 28 app.listen(3009);


// const add = (x,y) => x+y

// module.exports.addition = add

// module.exports ={
// add
// }

// exports ={
// add
// }

// exports.additionOp = add


// try{
//   require('./index1')
//   require('./index1')
//   require('./index1')
  
// } catch (err){
//   console.log("error")
//   throw new Error()
// }

// const fs require("fs").promises; 
// process.on("uncaughtexception", (err) => { console.log(caught exception: $(err)); 
// process.exit(1); }); 

// async function createcsv() { 
  
//   try { const csvheaders = "driver, team, points"; 
//   await fs.writefile("formula1.csv", csvheaders); }
//   catch (error) { console.error("got an error trying to write to a file: $[error.message)"); }
  
//   async function addream(driver, team, points) { try { 
//     const csvline = "\n$(driver), $(team), $(points)";
//     await fs.writefile("formula1.csv", csvline, { flag: "a" }); 
    
//   } catch (error) { console.error("got an error trying to write to a file: ${error.message)"); } }
  
//   async function read(sv() { await fs.readfile("filedoesnotexist.csv"); } (async function () { await createcsv(); await addteam("max", "redbull", 100); await readcsv(); await addteam("lewis", "mercedes", 103);


// const fs = require("fs"); 
// const zlib = require("zlib"); 
// const file = 'hello world';
// const { transform } = require("stream"); 
// const printprogress = new transform({ 
//   transform(chunk, encoding, callback) {
//     process.stdout.write("processing\n"); 
//     callback(null, chunk); } }); 
    
//     fs.createreadstream(file) 
//     .pipe(zlib.creategzip()) 
//     .pipe(printprogress) 
//     .pipe(fs.createwritestream(file + ".zip")) 
//     .on("finish", () => console.log("file processing complete"));


const{spawn}=require("child process');
const files=spawn("find . -type f | wc -1");
console.log(`number of files ${files}) ; 
by

NodeJS Online Compiler

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.

About NodeJS

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.

Key features

  • Built on Google chrome's javascript engine V8 and is pretty fast.
  • Node.js was developed by Ryan Dahl in 2009.
  • Server-side platform for building fast and scalable applications.
  • Node.js is Asynchronous, event-driven and works on single-thread model thus eliminating the dis-advantages of multi-thread model.
  • Supports various platforms like Windows, Linux, MacOS etc.
  • Provides rich library of java script modules which simplifies the development efforts.
  • Released under MIT license.

Express Framework

Express is one of the most popular web application framework in the NodeJS echosystem.

  • Pretty fast
  • Minimalist
  • Unopinionated
  • Very flexible

Syntax help

Examples

Using Moment

let moment = require('moment');

console.log(moment().format('MMMM Do YYYY, h:mm:ss a'));

Using Lodash

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}`);

Libraries supported

Following are the libraries supported by OneCompiler's NodeJS compiler.

  • lodash
  • moment
  • underscore
  • uuid
  • ejs
  • md5
  • url