Nodejs Join

Posted on  by admin
Table of contents
  • Enable auto login on this browser and speed through checkout every time. (Not recommended for shared devices.)What's this? You're logged in as. Automatically log in to PayPal for faster checkout without typing your password wherever you're logged in with your Google account.What's this? Linking your Google account allows you to activate One Touch quickly and easily when you check out.

Right Join

Already set up to use your mobile number to log in?

Otherwise, click the link to log in with email. Forgot your email address? Go to the PayPal website to retrieve it. PayPal One Touch™ only works for checkout. Please login with your email.

Please login with your email and password.

Join Two or More Tables

Something went wrong on our end. Please login with your email and password. Open the PayPal app, tap Yes on the prompt, then tap{twoDigitPin} on your phone to log in.

path.relative(from, to)#

Open the PayPal app and tap Yes on the prompt to log in. We didn't receive a response so we were unable confirm your identity. In this section, you will learn how to interact with SQLite databases from a Node.js application using the sqlite3 module.

After the tutorial, you will know how to open a database connection and perform common database operations such as select, insert, update, and delete. In addition, you will learn how to execute SQL statements in serialized mode or in parallel mode. The sqlite3 module is actively maintained and provides a rich set of features:. Simple API for query execution. Parameters binding support. Control the query execution flow, supporting both serialized and parallel modes. Comprehensive debugging support. Full caching / Blob support. SQLite extension support. Bundles SQLite as a fallback. To understand how the sqlite3 module works, you can use the following tutorials in sequence:.

Connecting to an SQLite3 database– shows you how to connect to an in-memory database or a file-based database. Querying data from tables – introduces you to various methods for querying data from tables. Controlling the execution flow of statements – explains the steps of executing multiple SQL statements in serialized mode or in parallel mode. Inserting data into a table – shows you how to insert one or more rows into a table.

Updating data – covers the steps of updating data in a table. Deleting data from a table – show you how to delete data from a table.

Left Join

You can combine rows from two or more tables, based on a related column between them, by using a JOIN statement. Consider you have a "users" table and a "products" table:.

path.resolve([...paths])#

  • [ { id: 1, name: 'John', favorite_product: 154}, { id: 2, name: 'Peter', favorite_product: 154}, { id: 3, name: 'Amy', favorite_product: 155}, { id: 4, name: 'Hannah', favorite_product:}, { id: 5, name: 'Michael', favorite_product:}].
  • [ { id: 154, name: 'Chocolate Heaven' }, { id: 155, name: 'Tasty Lemons' }, { id: 156, name: 'Vanilla Dreams' }]. These two tables can be combined by using users' favorite_product field and products' id field.

Select records with a match in both tables:.

path.delimiter#

  • var mysql = require('mysql'); var con = mysql.createConnection({ host: "localhost", user: "yourusername", password: "yourpassword", database: "mydb"});con.connect(function(err) { if (err) throw err; var sql = "SELECT users.name AS user, products.name AS favorite FROM users JOIN products ON users.favorite_product = products.id"; con.query(sql, function (err, result) { if (err) throw err; console.log(result); }); });.
  • Note: You can use INNER JOIN instead of JOIN. They will both give you the same result. Save the code above in a file called "demo_db_join.js" and run the file:.
  • Run "demo_db_join.js". Which will give you this result:. [ { user: 'John', favorite: 'Chocolate Heaven' }, { user: 'Peter', favorite: 'Chocolate Heaven' }, { user: 'Amy', favorite: 'Tasty Lemons' }].

As you can see from the result above, only the records with a match in both tables are returned. If you want to return all users, no matter if they have a favorite product or not, use the LEFT JOIN statement:.

path.extname(path)#

  • Select all users and their favorite product:. SELECT users.name AS user,products.name AS favoriteFROM usersLEFT JOIN products ON users.favorite_product = products.id.
  • Which will give you this result:. [ { user: 'John', favorite: 'Chocolate Heaven' }, { user: 'Peter', favorite: 'Chocolate Heaven' }, { user: 'Amy', favorite: 'Tasty Lemons' }, { user: 'Hannah', favorite: null }, { user: 'Michael', favorite: null }].
  • If you want to return all products, and the users who have them as their favorite, even if no user have them as their favorite, use the RIGHT JOIN statement:.

Select all products and the user who have them as their favorite:.

users

  • SELECT users.name AS user,products.name AS favoriteFROM usersRIGHT JOIN products ON users.favorite_product = products.id.
  • Which will give you this result:. [ { user: 'John', favorite: 'Chocolate Heaven' }, { user: 'Peter', favorite: 'Chocolate Heaven' }, { user: 'Amy', favorite: 'Tasty Lemons' }, { user: null, favorite: 'Vanilla Dreams' }].
  • Note: Hannah and Michael, who have no favorite product, are not included in the result.

Source Code:lib/path.js. The path module provides utilities for working with file and directory paths.It can be accessed using:.

Example

  • The default operation of the path module varies based on the operating systemon which a Node.js application is running.

Specifically, when running on aWindows operating system, the path module will assume that Windows-stylepaths are being used.

Path#

path.isAbsolute(path)#

  • So using path.basename() might yield different results on POSIX and Windows:. To achieve consistent results when working with Windows file paths on anyoperating system, use path.win32:. On POSIX and Windows:. To achieve consistent results when working with POSIX file paths on anyoperating system, use path.posix:. On POSIX and Windows:. On Windows Node.js follows the concept of per-drive working directory.This behavior can be observed when using a drive path without a backslash. Forexample, path.resolve('C:\\') can potentially return a different result thanpath.resolve('C:').

path.dirname(path)#

  • The path.dirname() method returns the directory name of a path, similar tothe Unix dirname command.

path.sep#

  • Trailing directory separators are ignored, seepath.sep. A TypeError is thrown if path is not a string.

path.join([...paths])#

  • Returns: .

path.normalize(path)#

  • The path.extname() method returns the extension of the path, from the lastoccurrence of the .

path.win32#

  • (period) character to end of string in the last portion ofthe path.

If there is no . in the last portion of the path, or ifthere are no .

path.posix#

  • characters other than the first character ofthe basename of path (see path.basename()) , an empty string is returned.
  • A TypeError is thrown if path is not a string. pathObject Any JavaScript object having the following properties:dirrootbasenameext.
  • Returns: .
  • The path.format() method returns a path string from an object. This is theopposite of path.parse().

    path.basename(path[, ext])#

    When providing properties to the pathObject remember that there arecombinations where one property has priority over another:.

    path.toNamespacedPath(path)#

    • pathObject.root is ignored if pathObject.dir is provided.

    pathObject.ext and pathObject.name are ignored if pathObject.base exists. For example, on POSIX:.

    products

    Returns: . The path.isAbsolute() method determines if path is an absolute path. If the given path is a zero-length string, false will be returned. For example, on POSIX:. A TypeError is thrown if path is not a string. ..paths A sequence of path segments.

    Windows vs. POSIX#

    Returns: . The path.join() method joins all given path segments together using theplatform-specific separator as a delimiter, then normalizes the resulting path.

    path.parse(path)#

    • Zero-length path segments are ignored. If the joined path string is azero-length string then '.'

    will be returned, representing the currentworking directory. A TypeError is thrown if any of the path segments is not a string. Returns: . The path.normalize() method normalizes the given path, resolving '.' When multiple, sequential path segment separation characters are found (e.g./ on POSIX and either \ or / on Windows), they are replaced by a singleinstance of the platform-specific path segment separator (/ on POSIX and\ on Windows).

    Trailing separators are preserved. If the path is a zero-length string, '.'

    is returned, representing thecurrent working directory. For example, on POSIX:. Since Windows recognizes multiple path separators, both separators will bereplaced by instances of the Windows preferred separator (\):.

    path.format(pathObject)#

    • A TypeError is thrown if path is not a string. Returns: .
    • The path.parse() method returns an object whose properties representsignificant elements of the path.
    • Trailing directory separators are ignored,see path.sep. The returned object will have the following properties:. For example, on POSIX:. A TypeError is thrown if path is not a string. The path.posix property provides access to POSIX specific implementationsof the path methods. The API is accessible via require('path').posix or require('path/posix'). Returns: . The path.relative() method returns the relative path from from to to basedon the current working directory.

      server.getConnections(callback)#

      • If from and to each resolve to the samepath (after calling path.resolve() on each), a zero-length string is returned.
      • If a zero-length string is passed as from or to, the current workingdirectory will be used instead of the zero-length strings.

      For example, on POSIX:. A TypeError is thrown if either from or to is not a string. ..paths A sequence of paths or path segments.

      Returns: . The path.resolve() method resolves a sequence of paths or path segments intoan absolute path.

      server.listen()#

      The given sequence of paths is processed from right to left, with eachsubsequent path prepended until an absolute path is constructed.For instance, given the sequence of path segments: /foo, /bar, baz,calling path.resolve('/foo', '/bar', 'baz') would return /bar/bazbecause 'baz' is not an absolute path but '/bar' + '/' + 'baz' is.

      If, after processing all given path segments, an absolute path has not yetbeen generated, the current working directory is used.

      • The resulting path is normalized and trailing slashes are removed unless thepath is resolved to the root directory.
      • Zero-length path segments are ignored. If no path segments are passed, path.resolve() will return the absolute pathof the current working directory.

      A TypeError is thrown if any of the arguments is not a string. Provides the platform-specific path segment separator:. For example, on POSIX:. On Windows, both the forward slash (/) and backward slash (\) are acceptedas path segment separators; however, the path methods only add backwardslashes (\).

      Returns: . On Windows systems only, returns an equivalent namespace-prefixed path forthe given path. If path is not a string, path will be returned withoutmodifications. This method is meaningful only on Windows systems.

      On POSIX systems, themethod is non-operational and always returns path without modifications. The path.win32 property provides access to Windows-specific implementationsof the path methods.

      The API is accessible via require('path').win32 or require('path/win32').

      One of the most common errors raised when listening is EADDRINUSE.This happens when another server is already listening on the requestedport/path/handle. One way to handle this would be to retryafter a certain amount of time:

      server.listen(handle[, backlog][, callback])#
      • handle
      • backlog Common parameter of server.listen() functions
      • callback
      • Returns:
      • Start a server listening for connections on a given handle that hasalready been bound to a port, a Unix domain socket, or a Windows named pipe.

        The handle object can be either a server, a socket (anything with anunderlying _handle member), or an object with an fd member that is avalid file descriptor.

        Listening on a file descriptor is not supported on Windows.

        server.listen(options[, callback])#
        • options Required. Supports the following properties:
          • port
          • host
          • path Will be ignored if port is specified. SeeIdentifying paths for IPC connections.
          • backlog Common parameter of server.listen()functions.
          • exclusiveDefault:false
          • readableAll For IPC servers makes the pipe readablefor all users. Default:false.
          • writableAll For IPC servers makes the pipe writablefor all users. Default:false.
          • ipv6Only For TCP servers, setting ipv6Only to true willdisable dual-stack support, i.e., binding to host :: won't make0.0.0.0 be bound. Default:false.
          • signal An AbortSignal that may be used to close a listening server.
        • callbackfunctions.
        • Returns:
        • If port is specified, it behaves the same asserver.listen([port[, host[, backlog]]][, callback]).Otherwise, if path is specified, it behaves the same asserver.listen(path[, backlog][, callback]).If none of them is specified, an error will be thrown.

          If exclusive is false (default), then cluster workers will use the sameunderlying handle, allowing connection handling duties to be shared. Whenexclusive is true, the handle is not shared, and attempted port sharingresults in an error. An example which listens on an exclusive port isshown below.

          When exclusive is true and the underlying handle is shared, it ispossible that several workers query a handle with different backlogs.In this case, the first backlog passed to the master process will be used.

          Starting an IPC server as root may cause the server path to be inaccessible forunprivileged users. Using readableAll and writableAll will make the serveraccessible for all users.

          If the signal option is enabled, calling .abort() on the correspondingAbortController is similar to calling .close() on the server:

          server.listen(path[, backlog][, callback])#
          • path Path the server should listen to. SeeIdentifying paths for IPC connections.
          • backlog Common parameter of server.listen() functions.
          • callback.
          • Returns:

          Start an IPC server listening for connections on the given path.

          server.listen([port[, host[, backlog]]][, callback])#
          • port
          • host
          • backlog Common parameter of server.listen() functions.
          • callback.
          • Returns:

          Start a TCP server listening for connections on the given port and host.

          If port is omitted or is 0, the operating system will assign an arbitraryunused port, which can be retrieved by using server.address().portafter the 'listening' event has been emitted.

          If host is omitted, the server will accept connections on theunspecified IPv6 address (::) when IPv6 is available, or theunspecified IPv4 address (0.0.0.0) otherwise.

          In most operating systems, listening to the unspecified IPv6 address (::)may cause the net.Server to also listen on the unspecified IPv4 address(0.0.0.0).

          server.listening#

          • Indicates whether or not the server is listening for connections.

          server.maxConnections#

          Set this property to reject connections when the server's connection count getshigh.

          It is not recommended to use this option once a socket has been sent to a childwith child_process.fork().

          server.ref()#

          • Returns:

          Opposite of unref(), calling ref() on a previously unrefed server willnot let the program exit if it's the only server left (the default behavior).If the server is refed calling ref() again will have no effect.

          server.unref()#

          • Returns:

          Calling unref() on a server will allow the program to exit if this is the onlyactive server in the event system. If the server is already unrefed callingunref() again will have no effect.

          Class: net.Socket#

          • Extends:

          This class is an abstraction of a TCP socket or a streaming IPC endpoint(uses named pipes on Windows, and Unix domain sockets otherwise). It is alsoan EventEmitter.

          A net.Socket can be created by the user and used directly to interact witha server. For example, it is returned by net.createConnection(),so the user can use it to talk to the server.

          It can also be created by Node.js and passed to the user when a connectionis received. For example, it is passed to the listeners of a'connection' event emitted on a net.Server, so the user can useit to interact with the client.

          new net.Socket([options])#

          • options Available options are:
            • fd If specified, wrap around an existing socket withthe given file descriptor, otherwise a new socket will be created.
            • allowHalfOpen If set to false, then the socket willautomatically end the writable side when the readable side ends. Seenet.createServer() and the 'end' event for details. Default:false.
            • readable Allow reads on the socket when an fd is passed,otherwise ignored. Default:false.
            • writable Allow writes on the socket when an fd is passed,otherwise ignored. Default:false.
            • signal An Abort signal that may be used to destroy thesocket.
          • Returns:
          • Creates a new socket object.

            The newly created socket can be either a TCP socket or a streaming IPCendpoint, depending on what it connect() to.

            Event: 'close'#

            • hadErrortrue if the socket had a transmission error.

            Emitted once the socket is fully closed. The argument hadError is a booleanwhich says if the socket was closed due to a transmission error.

            Event: 'connect'#

            Emitted when a socket connection is successfully established.See net.createConnection().

            Event: 'data'#

            • |

            Emitted when data is received. The argument data will be a Buffer orString. Encoding of data is set by socket.setEncoding().

            The data will be lost if there is no listener when a Socketemits a 'data' event.

            Event: 'drain'#

            Emitted when the write buffer becomes empty. Can be used to throttle uploads.

            See also: the return values of socket.write().

            Event: 'end'#

            Emitted when the other end of the socket signals the end of transmission, thusending the readable side of the socket.

            By default (allowHalfOpen is false) the socket will send an end oftransmission packet back and destroy its file descriptor once it has written outits pending write queue. However, if allowHalfOpen is set to true, thesocket will not automatically end() its writable side,allowing the user to write arbitrary amounts of data. The user must callend() explicitly to close the connection (i.e. sending aFIN packet back).

            Event: 'error'#

            Emitted when an error occurs. The 'close' event will be called directlyfollowing this event.

            Event: 'lookup'#

            Emitted after resolving the host name but before connecting.Not applicable to Unix sockets.

            • err | The error object. See dns.lookup().
            • address The IP address.
            • family | The address type. See dns.lookup().
            • host The host name.

            Event: 'ready'#

            Emitted when a socket is ready to be used.

            Triggered immediately after 'connect'.

            Event: 'timeout'#

            Emitted if the socket times out from inactivity. This is only to notify thatthe socket has been idle. The user must manually close the connection.

            See also: socket.setTimeout().

            socket.address()#

            • Returns:

              Returns the bound address, the address family name and port of thesocket as reported by the operating system:{ port: 12346, family: 'IPv4', address: '127.0.0.1' }

              socket.bufferSize#

              Stability: 0 - Deprecated: Use writable.writableLength instead.

              This property shows the number of characters buffered for writing. The buffermay contain strings whose length after encoding is not yet known. So this numberis only an approximation of the number of bytes in the buffer.

              net.Socket has the property that socket.write() always works. This is tohelp users get up and running quickly. The computer cannot always keep upwith the amount of data that is written to a socket. The network connectionsimply might be too slow. Node.js will internally queue up the data written to asocket and send it out over the wire when it is possible.

              The consequence of this internal buffering is that memory may grow.Users who experience large or growing bufferSize should attempt to"throttle" the data flows in their program withsocket.pause() and socket.resume().

              socket.bytesRead#

              The amount of received bytes.

              socket.bytesWritten#

              The amount of bytes sent.

              socket.connect()#

              Initiate a connection on a given socket.

              Possible signatures:

              • socket.connect(path[, connectListener])for IPC connections.
              • socket.connect(port[, host][, connectListener])for TCP connections.
              • Returns: The socket itself.

              This function is asynchronous. When the connection is established, the'connect' event will be emitted. If there is a problem connecting,instead of a 'connect' event, an 'error' event will be emitted withthe error passed to the 'error' listener.The last parameter connectListener, if supplied, will be added as a listenerfor the 'connect' event once.

              This function should only be used for reconnecting a socket after'close' has been emitted or otherwise it may lead to undefinedbehavior.

              socket.connect(options[, connectListener])#
              • options
              • connectListener Common parameter of socket.connect()methods. Will be added as a listener for the 'connect' event once.
              • Returns: The socket itself.
              • Initiate a connection on a given socket. Normally this method is not needed,the socket should be created and opened with net.createConnection(). Usethis only when implementing a custom Socket.

                For TCP connections, available options are:

                • port Required. Port the socket should connect to.
                • host Host the socket should connect to. Default:'localhost'.
                • localAddress Local address the socket should connect from.
                • localPort Local port the socket should connect from.
                • family: Version of IP stack. Must be 4, 6, or 0. The value0 indicates that both IPv4 and IPv6 addresses are allowed. Default:0.
                • hints Optional dns.lookup() hints.
                • lookup Custom lookup function. Default:dns.lookup().
                • noDelay If set to true, it disables the use of Nagle's algorithm immediatelyafter the socket is established. Default:false.
                • keepAlive If set to true, it enables keep-alive functionality on the socketimmediately after the connection is established, similarly on what is done insocket.setKeepAlive([enable][, initialDelay]).Default:false.
                • keepAliveInitialDelay If set to a positive number, it sets the initial delay beforethe first keepalive probe is sent on an idle socket.Default:0.

                For IPC connections, available options are:

                • path Required. Path the client should connect to.See Identifying paths for IPC connections. If provided, the TCP-specificoptions above are ignored.

                For both types, available options include:

                • onread If specified, incoming data is stored in a single bufferand passed to the supplied callback when data arrives on the socket.This will cause the streaming functionality to not provide any data.The socket will emit events like 'error', 'end', and 'close'as usual. Methods like pause() and resume() will also behave asexpected.
                  • buffer | | Either a reusable chunk of memory touse for storing incoming data or a function that returns such.
                  • callback This function is called for every chunk of incomingdata. Two arguments are passed to it: the number of bytes written tobuffer and a reference to buffer. Return false from this function toimplicitly pause() the socket. This function will be executed in theglobal context.

                  Following is an example of a client using the onread option:

                  socket.connect(path[, connectListener])#
                  • path Path the client should connect to. SeeIdentifying paths for IPC connections.
                  • connectListener Common parameter of socket.connect()methods. Will be added as a listener for the 'connect' event once.
                  • Returns: The socket itself.

                  Initiate an IPC connection on the given socket.

                  Alias tosocket.connect(options[, connectListener])called with { path: path } as options.

                  socket.connect(port[, host][, connectListener])#
                  • port Port the client should connect to.
                  • host Host the client should connect to.
                  • connectListener Common parameter of socket.connect()methods. Will be added as a listener for the 'connect' event once.
                  • Returns: The socket itself.

                  Initiate a TCP connection on the given socket.

                  Alias tosocket.connect(options[, connectListener])called with {port: port, host: host} as options.

                  socket.connecting#

                  If true,socket.connect(options[, connectListener]) wascalled and has not yet finished. It will stay true until the socket becomesconnected, then it is set to false and the 'connect' event is emitted. Notethat thesocket.connect(options[, connectListener])callback is a listener for the 'connect' event.

                  socket.destroy([error])#

                  • error
                  • Returns:
                  • Ensures that no more I/O activity happens on this socket.Destroys the stream and closes the connection.

                    See writable.destroy() for further details.

                    socket.destroyed#

                    • Indicates if the connection is destroyed or not. Once aconnection is destroyed no further data can be transferred using it.

                    See writable.destroyed for further details.

                    socket.end([data[, encoding]][, callback])#

                    • data | |
                    • encoding Only used when data is string. Default:'utf8'.
                    • callback Optional callback for when the socket is finished.
                    • Returns: The socket itself.

                    Half-closes the socket. i.e., it sends a FIN packet. It is possible theserver will still send some data.

                    See writable.end() for further details.

                    socket.localAddress#

                    The string representation of the local IP address the remote client isconnecting on. For example, in a server listening on '0.0.0.0', if a clientconnects on '192.168.1.1', the value of socket.localAddress would be'192.168.1.1'.

                    socket.localPort#

                    The numeric representation of the local port. For example, 80 or 21.

                    socket.pause()#

                    • Returns: The socket itself.

                    Pauses the reading of data. That is, 'data' events will not be emitted.Useful to throttle back an upload.

                    socket.pending#

                    This is true if the socket is not connected yet, either because .connect()has not yet been called or because it is still in the process of connecting(see socket.connecting).

                    socket.ref()#

                    • Returns: The socket itself.

                    Opposite of unref(), calling ref() on a previously unrefed socket willnot let the program exit if it's the only socket left (the default behavior).If the socket is refed calling ref again will have no effect.

                    socket.remoteAddress#

                    The string representation of the remote IP address. For example,'74.125.127.100' or '2001:4860:a005::68'. Value may be undefined ifthe socket is destroyed (for example, if the client disconnected).

                    socket.remoteFamily#

                    The string representation of the remote IP family. 'IPv4' or 'IPv6'.

                    socket.remotePort#

                    The numeric representation of the remote port. For example, 80 or 21.

                    socket.resume()#

                    • Returns: The socket itself.

                    Resumes reading after a call to socket.pause().

                    socket.setEncoding([encoding])#

                    • encoding
                    • Returns: The socket itself.

                    Set the encoding for the socket as a Readable Stream. Seereadable.setEncoding() for more information.

                    socket.setKeepAlive([enable][, initialDelay])#

                    • enableDefault:false
                    • initialDelayDefault:0
                    • Returns: The socket itself.

                    Enable/disable keep-alive functionality, and optionally set the initialdelay before the first keepalive probe is sent on an idle socket.

                    Set initialDelay (in milliseconds) to set the delay between the lastdata packet received and the first keepalive probe. Setting 0 forinitialDelay will leave the value unchanged from the default(or previous) setting.

                    Enabling the keep-alive functionality will set the following socket options:

                    • SO_KEEPALIVE=1
                    • TCP_KEEPIDLE=initialDelay
                    • TCP_KEEPCNT=10
                    • TCP_KEEPINTVL=1

                    socket.setNoDelay([noDelay])#

                    • noDelayDefault:true
                    • Returns: The socket itself.

                    Enable/disable the use of Nagle's algorithm.

                    When a TCP connection is created, it will have Nagle's algorithm enabled.

                    Nagle's algorithm delays data before it is sent via the network. It attemptsto optimize throughput at the expense of latency.

                    Passing true for noDelay or not passing an argument will disable Nagle'salgorithm for the socket. Passing false for noDelay will enable Nagle'salgorithm.

                    socket.setTimeout(timeout[, callback])#

                    • timeout
                    • callback
                    • Returns: The socket itself.

                    Sets the socket to timeout after timeout milliseconds of inactivity onthe socket. By default net.Socket do not have a timeout.

                    When an idle timeout is triggered the socket will receive a 'timeout'event but the connection will not be severed. The user must manually callsocket.end() or socket.destroy() to end the connection.

                    If timeout is 0, then the existing idle timeout is disabled.

                    The optional callback parameter will be added as a one-time listener for the'timeout' event.

                    socket.timeout#

                    • |

                    The socket timeout in milliseconds as set by socket.setTimeout().It is undefined if a timeout has not been set.

                    socket.unref()#

                    • Returns: The socket itself.

                    Calling unref() on a socket will allow the program to exit if this is the onlyactive socket in the event system. If the socket is already unrefed callingunref() again will have no effect.

                    socket.write(data[, encoding][, callback])#

                    • data | |
                    • encoding Only used when data is string. Default:utf8.
                    • callback
                    • Returns:

                    Sends data on the socket. The second parameter specifies the encoding in thecase of a string. It defaults to UTF8 encoding.

                    Returns true if the entire data was flushed successfully to the kernelbuffer. Returns false if all or part of the data was queued in user memory.'drain' will be emitted when the buffer is again free.

                    The optional callback parameter will be executed when the data is finallywritten out, which may not be immediately.

                    See Writable stream write() method for moreinformation.

                    socket.readyState#

                    This property represents the state of the connection as a string.

                    • If the stream is connecting socket.readyState is opening.
                    • If the stream is readable and writable, it is open.
                    • If the stream is readable and not writable, it is readOnly.
                    • If the stream is not readable and writable, it is writeOnly.

                    net.connect()#

                    Aliases tonet.createConnection().

                    Possible signatures:

                    • net.connect(path[, connectListener]) for IPCconnections.
                    • net.connect(port[, host][, connectListener])for TCP connections.

                    net.connect(options[, connectListener])#

                    • options
                    • connectListener
                    • Returns:
                    • Alias tonet.createConnection(options[, connectListener]).

                      net.connect(path[, connectListener])#

                      • path
                      • connectListener
                      • Returns:

                      Alias tonet.createConnection(path[, connectListener]).

                      net.connect(port[, host][, connectListener])#

                      • port
                      • host
                      • connectListener
                      • Returns:

                      Alias tonet.createConnection(port[, host][, connectListener]).

                      net.createConnection()#

                      A factory function, which creates a new net.Socket,immediately initiates connection with socket.connect(),then returns the net.Socket that starts the connection.

                      When the connection is established, a 'connect' event will be emittedon the returned socket. The last parameter connectListener, if supplied,will be added as a listener for the 'connect' event once.

                      Possible signatures:

                      • net.createConnection(path[, connectListener])for IPC connections.
                      • net.createConnection(port[, host][, connectListener])for TCP connections.

                      The net.connect() function is an alias to this function.

                      net.createConnection(options[, connectListener])#

                      • options Required. Will be passed to both thenew net.Socket([options]) call and thesocket.connect(options[, connectListener])method.
                      • connectListener Common parameter of thenet.createConnection() functions. If supplied, will be added asa listener for the 'connect' event on the returned socket once.
                      • Returns: The newly created socket used to start the connection.
                      • For available options, seenew net.Socket([options])and socket.connect(options[, connectListener]).

                        Additional options:

                        • timeout If set, will be used to callsocket.setTimeout(timeout) after the socket is created, but beforeit starts the connection.

                        Following is an example of a client of the echo server describedin the net.createServer() section:

                        To connect on the socket /tmp/echo.sock:

                        net.createConnection(path[, connectListener])#

                        • path Path the socket should connect to. Will be passed tosocket.connect(path[, connectListener]).See Identifying paths for IPC connections.
                        • connectListener Common parameter of thenet.createConnection() functions, an "once" listener for the'connect' event on the initiating socket. Will be passed tosocket.connect(path[, connectListener]).
                        • Returns: The newly created socket used to start the connection.

                        Initiates an IPC connection.

                        This function creates a new net.Socket with all options set to default,immediately initiates connection withsocket.connect(path[, connectListener]),then returns the net.Socket that starts the connection.

                        net.createConnection(port[, host][, connectListener])#

                        • port Port the socket should connect to. Will be passed tosocket.connect(port[, host][, connectListener]).
                        • host Host the socket should connect to. Will be passed tosocket.connect(port[, host][, connectListener]).Default:'localhost'.
                        • connectListener Common parameter of thenet.createConnection() functions, an "once" listener for the'connect' event on the initiating socket. Will be passed tosocket.connect(port[, host][, connectListener]).
                        • Returns: The newly created socket used to start the connection.

                        Initiates a TCP connection.

                        This function creates a new net.Socket with all options set to default,immediately initiates connection withsocket.connect(port[, host][, connectListener]),then returns the net.Socket that starts the connection.

                        net.createServer([options][, connectionListener])#

                        • options

                          • allowHalfOpen If set to false, then the socket willautomatically end the writable side when the readable side ends.Default:false.
                          • pauseOnConnect Indicates whether the socket should bepaused on incoming connections. Default:false.
                          • noDelay If set to true, it disables the use of Nagle's algorithm immediatelyafter a new incoming connection is received. Default:false.
                          • keepAlive If set to true, it enables keep-alive functionality on the socketimmediately after a new incoming connection is received, similarly on what is done insocket.setKeepAlive([enable][, initialDelay]).Default:false.
                          • keepAliveInitialDelay If set to a positive number, it sets the initial delay beforethe first keepalive probe is sent on an idle socket.Default:0.
                        • connectionListener Automatically set as a listener for the'connection' event.

                        • Returns:

                        • Creates a new TCP or IPC server.

                          If allowHalfOpen is set to true, when the other end of the socketsignals the end of transmission, the server will only send back the end oftransmission when socket.end() is explicitly called. For example, in thecontext of TCP, when a FIN packed is received, a FIN packed is sentback only when socket.end() is explicitly called. Until then theconnection is half-closed (non-readable but still writable). See 'end'event and RFC 1122 (section 4.2.2.13) for more information.

                          If pauseOnConnect is set to true, then the socket associated with eachincoming connection will be paused, and no data will be read from its handle.This allows connections to be passed between processes without any data beingread by the original process. To begin reading data from a paused socket, callsocket.resume().

                          The server can be a TCP server or an IPC server, depending on what itlisten() to.

                          Here is an example of a TCP echo server which listens for connectionson port 8124:

                          Test this by using telnet:

                          To listen on the socket /tmp/echo.sock:

                          Use nc to connect to a Unix domain socket server:

                          net.isIP(input)#

                          • input
                          • Returns:

                          Returns 6 if input is an IPv6 address. Returns 4 if input is an IPv4address in dot-decimal notation with no leading zeroes. Otherwise, returns0.

                          net.isIPv4(input)#

                          • input
                          • Returns:

                          Returns true if input is an IPv4 address in dot-decimal notation with noleading zeroes. Otherwise, returns false.

                          net.isIPv6(input)#

                          • input
                          • Returns:

                          Returns true if input is an IPv6 address. Otherwise, returns false.