You want to serve files using the Trivial File Transfer Protocol? Well, then this module might be the one you are looking for.
const TFTP = require('tftp-server');
const srv = TFTP.createServer();
Creates a new TFTP server and returns an instance of TFTPServer
.
Don't instantiate this class directly. You should use the factory function TFTP.createServer()
.
const handle = srv.register([filter, ]handler);
Registers a new request handler.
The optional filter
can be a string or a regular expression. The handler will only be called if the filter matches. If filter is omitted, the handler will be called on every request.
The handler
is a function with the following interface: (req, res, next) => {...}
. The parameters:
req
: An object describing the current request:req.filename
: The requested file name. This comes in handy if filter is omitted or a regular expression.req.mode
: The stated transmission mode.
res
: A function that awaits aBuffer
as the first argument. If it is called, the buffer is transmitted to the client. No other handlers will be called.next
: A function that takes an optional argument. If the argument is an instance ofError
, an ERROR packet is sent to the client. If the argument is omitted, the next registered handler is called.
If no matching handler is found that called res
, a "File not found" error is sent to the client.
srv.unregister(handle);
This removes the handler addressed by the given handle
.
srv.bind(options);
Binds the server. For further details about options
please have a look into the Node.js API docs for UDP/Datagram.
srv.destroy([cb]);
Closes all connections and sockets.