Modulo di utilità Node.js
Esempio
Formatta una stringa usando gli argomenti "Linus" e "6":
var util = require('util');
var txt = 'Congratulate %s on his %dth
birthday!';
var result = util.format(txt, 'Linus', 6);
console.log(result);
Definizione e utilizzo
Il modulo Util fornisce l'accesso ad alcune funzioni di utilità.
Sintassi
La sintassi per includere il modulo Util nell'applicazione:
var util = require('util');
Proprietà e metodi di Util
Method | Description |
---|---|
debuglog() | Writes debug messages to the error object |
deprecate() | Marks the specified function as deprecated |
format() | Formats the specified string, using the specified arguments |
inherits() | Inherits methods from one function into another |
inspect() | Inspects the specified object and returns the object as a string |