Node has many deprecated API. The community is going to remove those API from Node in future, so we should not use those.
Examples of 👎 incorrect code for this rule:
/*eslint node/no-deprecated-api: "error" */
var fs = require("fs");
fs.exists("./foo.js", function() {}); /*ERROR: 'fs.exists' was deprecated since v4. Use 'fs.stat()' or 'fs.access()' instead.*/
// Also, it can report the following patterns.
var exists = require("fs").exists; /*ERROR: 'fs.exists' was deprecated since v4. Use 'fs.stat()' or 'fs.access()' instead.*/
const {exists} = require("fs"); /*ERROR: 'fs.exists' was deprecated since v4. Use 'fs.stat()' or 'fs.access()' instead.*/
// And other deprecated API below.
This rule reports the following deprecated API.
- buffer
- Buffer constructors (Use safe-buffer module for
Node@<4.5.0
) - SlowBuffer class
- Buffer constructors (Use safe-buffer module for
- crypto
- domain
- events
- fs
- globals
- require.extensions
Intl.v8BreakIterator
(undocumented)
- http
- module
requireRepl
(undocumented)
- os
tmpDir
(undocumented)
- process
EventEmitter
(undocumented)
- punycode
- readline
codePointAt
(undocumented)getStringWidth
(undocumented)isFullWidthCodePoint
(undocumented)stripVTControlCharacters
(undocumented)
- repl
- tls
- CleartextStream (this class was removed on v0.11.3, but never deprecated in documents)
- CryptoStream
- SecurePair
- createSecurePair
- tty
- util
This rule has 2 options.
{
"rules": {
"node/no-deprecated-api": ["error", {
"ignoreModuleItems": [],
"ignoreGlobalItems": [],
"ignoreIndirectDependencies": false
}]
}
}
This is the array of module names and module's member names. Default is an empty array.
This rule ignores APIs that ignoreModuleItems
includes.
This option can include the following values:
buffer.Buffer()
new buffer.Buffer()
buffer.SlowBuffer
crypto.createCredentials
domain
events.EventEmitter.listenerCount
events.listenerCount
fs.exists
http.createClient
module.Module.requireRepl
module.requireRepl
os.tmpDir
punycode
readline.codePointAt
readline.getStringWidth
readline.isFullWidthCodePoint
readline.stripVTControlCharacters
tls.CleartextStream
tls.CryptoStream
tls.SecurePair
tls.createSecurePair
tty.setRawMode
util.debug
util.error
util.isArray
util.isBoolean
util.isBuffer
util.isDate
util.isError
util.isFunction
util.isNull
util.isNullOrUndefined
util.isNumber
util.isObject
util.isPrimitive
util.isRegExp
util.isString
util.isSymbol
util.isUndefined
util.log
util.print
util.pump
util.puts
util._extend
Examples of 👍 correct code for the {"ignoreModuleItems": ["new buffer.Buffer()"]}
:
/*eslint node/no-deprecated-api: [error, {ignoreModuleItems: ["new buffer.Buffer()"]}] */
const buffer = require("buffer")
const data = new buffer.Buffer(10) // OK since it's in ignoreModuleItems.
This is the array of global variable names and global variable's member names. Default is an empty array.
This rule ignores APIs that ignoreGlobalItems
includes.
This option can include the following values:
Buffer()
new Buffer()
Intl.v8BreakIterator
require.extensions
process.EventEmitter
process.env.NODE_REPL_HISTORY_FILE
Examples of 👍 correct code for the {"ignoreGlobalItems": ["new Buffer()"]}
:
/*eslint node/no-deprecated-api: [error, {ignoreGlobalItems: ["new Buffer()"]}] */
const data = new Buffer(10) // OK since it's in ignoreGlobalItems.
If ignoreIndirectDependencies: true
, this rule ignores deprecated APIs if your module depends on third-party modules which have the same name as core modules indirectly. Default is false
.
If your module depends on such third-party modules directly (explicitly), this rule always ignores deprecated APIs of those.
This rule cannot report the following cases:
- cluster
- crypto
- net
- repl
replServer.convertToContext
(undocumented)
require(foo).aDeprecatedProperty;
require("http")[A_DEPRECATED_PROPERTY]();
var obj = {
Buffer: require("buffer").Buffer
};
new obj.Buffer(); /* missing. */
var obj = {};
obj.Buffer = require("buffer").Buffer
new obj.Buffer(); /* missing. */
(function(Buffer) {
new Buffer(); /* missing. */
})(require("buffer").Buffer);
var Buffer = require("buffer").Buffer;
Buffer = require("another-buffer");
new Buffer(); /*ERROR: 'buffer.Buffer' constructor was deprecated.*/