Sunday 30 September 2018

node.js tutorial

Introduction

Introduction to Node.js
Installation and setup
Hello World Application
REPL: Exit from the prompt
REPL: list all the commands
Exploring node package manager (npm)
npm: Global vs local installation of modules
npm: Adding dependencies to node.js application
What is npmjs?
Node.js: Callback example

Node.js: Global Objects

Global Objects
Exploring console object
    Evaluate the expressions in console messages
    console.assert(value[, ...message])
    console.clear(): Clear the messages on terminal
    console.count([label]): Maintains internal counter for the label
    console.countReset([label]): Reset the counter for this label
    console.debug(data[, ...args])
    console.dir(obj[, options])
    console.dirxml(...data): Logs the information
    console.error([data][, ...args])
    console.group([...label]): logs message with indentation
    console.groupCollapsed(): Log the messages with indentation
    console.groupEnd(): Decreases the indentation while logging
    console.info([data][, ...args]): logs the message
    console.log([data][, ...args]): logs the message
    console.table(tabularData[, properties]): logs table data
    console.time([label]): Compute the duration of an operation console.time([label])
    console.timeEnd([label]): Stops a timer
    console.timeLog([label][, ...data]): Print the elapsed time
    console.trace([message][, ...args]): Log the stack trace
    console.warn([data][, ...args]): Log warning message
__dirname: Get the directory name of current module
__filename: Absolute path of the current module file
require(): Load required modules
Process object
    process.stdout: Write to standard output
    process.stdin: Read input
    process.exit: Exit current process
timing functions
process.stdout clearLine() and cursorTo methods

Core Modules

Introduction to Core Modules
Exploring readline module
    readline: close event
    readline: line event
    readline : pause event
    readline: resume event
    readline: SIGINT event
    Readline: close method
    Readline: pause method
    Readline: rl.prompt([preserveCursor])
    readline: rl.question(query, callback)
    readline: rl.setPrompt(prompt)
    readline: rl.write(data[, key])
    readline.clearLine(stream, dir)
    readline.clearScreenDown(stream)
    readline.createInterface(options)
    readline.createInterface(options): How to use completer function?
    readline.cursorTo(stream, x, y)
    readline.emitKeypressEvents(stream[, interface])
    readline.moveCursor(stream, dx, dy)
    readline: Building simple command line interface
    readline: How to read a file
Exploring events module
    Implementing custom event emitter
    asynchronous and synchronous way of calling listeners
    emitter.once(eventName, listener): Handle the event only once
    Error handling of events
    Exploring EventEmitter class
        newListener event
        removeListener event
        How to set the maximum listeners for specific emitter instance?
        emitter.addListener(eventName, listener): Add listener to this event
        emitter.emit(eventName[, ...args])
        emitter.eventNames()
        emitter.getMaxListeners()
        emitter.listenerCount(eventName)
        emitter.off(eventName, listener)
        emitter.on(eventName, listener)
        emitter.once(eventName, listener)
        emitter.prependListener(eventName, listener)
         emitter.prependOnceListener(eventName, listener)
        emitter.removeAllListeners([eventName])
        emitter.removeListener(eventName, listener)
        emitter.setMaxListeners(n)
        emitter.rawListeners(eventName)
Exporting custom modules
Error-first callbacks
Working with file system (fs) module
    fs.readdirSync(path[, options]): list all the files in a directory
    readdir(path[, options], callback): list files asynchronously
    readFileSync(path[, options]): Return the contents of the file
    fs.readFile(path[, options], callback): Read file asynchronously
    child_process.exec(command[, options][, callback]) : Execute system commands
    fs.statSync(path[, options]): get the statistics or information about a file
    fs.writeFileSync(file, data[, options]): Write data to the file
    fs.writeFile(file, data[, options], callback): Write data to a file asynchronously
    fs.appendFileSync(path, data[, options]): Append data to a file synchronously
    fs.appendFile(path, data[, options], callback): Append data to a file synchronously
    fs.existsSync(path): Check for the existence of a file
    fs.mkdirSync(path[, mode]): Creates a directory synchronously
    fs.mkdir(path[, mode], callback): Create a directory asynchronously
    fs.renameSync(oldPath, newPath): Rename a file
    fs.rename(oldPath, newPath, callback): Rename the file asynchronously
    fs.unlinkSync(path): Remove a file or symbolic link asynchronously
    fs.unlink(path, callback): Remove a file or symbolic link asynchronously
    fs.rmdirSync(path): Remove a directory synchronously
    fs.rmdir(path, callback): Remove a directory asynchronously
    Recursively remove a directory
    fs.createReadStream(path[, options]): Create readable stream
    fs.createWriteStream(path[, options]): Working with Writeable stream
Working with http module
    Make http request
    http.createServer([options][, requestListener]): Building Hello World web application
    http: Serve files
    Serving html page
    Load json file using require function
    http: Handle post requests

Miscellaneous

child_process.spawn(command[, args][, options]): Spawns a new process
Node cli: --trace-warnings

Previous                                                 Next                                                 Home

No comments:

Post a Comment