Error eexist file already exists mkdir

Is this a Feature or Bug? Bug Current behavior: When installing and running Cypress on Windows, I get the following error: Error: EEXIST: file already exists, mkdir 'C:UsersaaronRoamingnode...
Wed, 20 Dec 2017 02:09:32 GMT cypress:ts Running without ts-node hook in environment "production"
Wed, 20 Dec 2017 02:09:33 GMT cypress:server:appdata path: C:UsersaaronAppDatatmpCypresscyproduction
Wed, 20 Dec 2017 02:09:33 GMT cypress:server starting cypress server
Wed, 20 Dec 2017 02:09:33 GMT cypress:server:appdata path: C:UsersaaronAppDatatmpCypresscyproduction
Wed, 20 Dec 2017 02:09:37 GMT cypress:server start in mode headed with options {"_":["C:\Users\aaron\tmp\node_modules\cypress\dist\Cypress\Cypress.exe"],"project":"C:\Users\aaron\tmp\node_modules\.bin","projectPath":"C:\Users\aaron\tmp\node_modules\.bin"}
Wed, 20 Dec 2017 02:09:43 GMT cypress:server:appdata path: C:UsersaaronAppDatatmpCypresscyproductionbrowsers
Wed, 20 Dec 2017 02:09:44 GMT cypress:server:appdata path: C:UsersaaronAppDatatmpCypresscyproductioncache
Wed, 20 Dec 2017 02:10:00 GMT cypress:server:timers queuing timer id 1 after 500 ms
Wed, 20 Dec 2017 02:10:00 GMT cypress:server:timers child received timer id 1
Wed, 20 Dec 2017 02:10:00 GMT cypress:server:timers child sending timer id 1
Wed, 20 Dec 2017 02:10:00 GMT cypress:server:timers clearing timer id 1 from queue { '1': { args: [], ms: 500, cb: [Function] } }
Wed, 20 Dec 2017 02:10:00 GMT cypress:server making saved state from C:Usersaarontmpnode_modulescypressdistCypressresourcesapppackagesserver
Wed, 20 Dec 2017 02:10:00 GMT cypress:server for project path C:Usersaarontmpnode_modules.bin
Wed, 20 Dec 2017 02:10:00 GMT cypress:server state path for project C:Usersaarontmpnode_modules.bin
Wed, 20 Dec 2017 02:10:00 GMT cypress:server:appdata path: C:UsersaaronAppDatatmpCypresscyproductionprojects.bin-51b4388fba0de7ac28bff8df9045a210state.json
Wed, 20 Dec 2017 02:10:00 GMT cypress:server full state path C:UsersaaronAppDatatmpCypresscyproductionprojects.bin-51b4388fba0de7ac28bff8df9045a210state.json
Wed, 20 Dec 2017 02:10:00 GMT cypress:server making new state file around C:UsersaaronAppDatatmpCypresscyproductionprojects.bin-51b4388fba0de7ac28bff8df9045a210state.json
Wed, 20 Dec 2017 02:10:00 GMT cypress:server:file reading JSON file C:UsersaaronAppDatatmpCypresscyproductionprojects.bin-51b4388fba0de7ac28bff8df9045a210state.json
Wed, 20 Dec 2017 02:10:00 GMT cypress:server:windows creating electron window with options { backgroundColor: '#dfe2e4', width: 800, height: 550, minWidth: 458, minHeight: 400, x: null, y: null, type: 'INDEX', devTools: false, trackState: { width: 'appWidth', height: 'appHeight', x: 'appX', y: 'appY', devTools: 'isAppDevToolsOpen' }, onBlur: [Function: onBlur], onFocus: [Function: onFocus], onClose: [Function: onClose], show: true, url: 'file://C:\Users\aaron\tmp\node_modules\cypress\dist\Cypress\resources\app\packages\desktop-gui\dist\index.html', webPreferences: { preload: 'C:\Users\aaron\tmp\node_modules\cypress\dist\Cypress\resources\app\packages\server\lib\ipc\ipc.js', chromeWebSecurity: true, nodeIntegration: false, backgroundThrottling: false, backgroundColor: '#dfe2e4' }, frame: true, contextMenu: false, recordFrameRate: null, onPaint: null, onCrashed: [Function: onCrashed], onNewWindow: [Function: onNewWindow] }
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events got request for event: on:menu:clicked undefined
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events got request for event: get:options undefined
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events sending ipc data { type: 'get:options',
  data: 
   { id: 0.6289514760541144,
     data: 
      { _: [Object],
        project: 'C:\Users\aaron\tmp\node_modules\.bin',
        projectPath: 'C:\Users\aaron\tmp\node_modules\.bin',
        onFocusTests: [Function: onFocusTests],
        os: 'win32',
        version: '1.4.0' } } }
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events got request for event: get:current:user undefined
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:file reading JSON file C:UsersaaronAppDatatmpCypresscyproductioncache
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events sending ipc data { type: 'get:current:user',
  data: { id: 0.3762137311755782, data: {} } }
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events got request for event: on:focus:tests undefined
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events got request for event: on:spec:changed undefined
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events got request for event: on:config:changed undefined
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events got request for event: on:project:error undefined
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events got request for event: on:project:warning undefined
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events got request for event: open:project C:Usersaarontmpnode_modules.bin
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:project Project created C:Usersaarontmpnode_modules.bin
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events got request for event: updater:check undefined
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:updater checking for new version of Cypress. current version is 1.4.0
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher checking one browser chrome
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher looking up chrome on win32 platform
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher exe path C:Program Files (x86)GoogleChromeApplicationchrome.exe
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher found C:Program Files (x86)GoogleChromeApplicationchrome.exe ? true
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher Version=63.0.3239.84
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher browser chrome at 'C:Program Files (x86)GoogleChromeApplicationchrome.exe' version 63.0.3239.84
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher setting major version for {"name":"chrome","displayName":"Chrome","version":"63.0.3239.84","path":"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"}
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher browser chrome version 63.0.3239.84 major version 63
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher checking one browser chromium
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher looking up chromium on win32 platform
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher exe path C:Program Files (x86)Googlechrome-win32chrome.exe
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher found C:Program Files (x86)Googlechrome-win32chrome.exe ? false
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher browser chromium not installed
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher checking one browser canary
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher looking up canary on win32 platform
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher exe path C:UsersaaronAppDataLocalGoogleChrome SxSApplicationchrome.exe
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher found C:UsersaaronAppDataLocalGoogleChrome SxSApplicationchrome.exe ? false
Wed, 20 Dec 2017 02:10:02 GMT cypress:launcher browser canary not installed
Wed, 20 Dec 2017 02:10:02 GMT cypress:server opening project C:Usersaarontmpnode_modules.bin
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:project opening project instance C:Usersaarontmpnode_modules.bin
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:config setting support file C:Usersaarontmpnode_modules.bincypresssupport
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:config for project root C:Usersaarontmpnode_modules.bin
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:config support file C:Usersaarontmpnode_modules.bincypresssupport does not exist
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:config support file is default, check if C:Usersaarontmpnode_modules.bincypress exists
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:config support folder does not exist, set to default index.js
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:config set support folder C:Usersaarontmpnode_modules.bincypresssupport
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:config setting plugins file C:Usersaarontmpnode_modules.bincypressplugins
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:config for project root C:Usersaarontmpnode_modules.bin
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:config plugins file does not exist
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:config plugins file is default, check if C:Usersaarontmpnode_modules.bincypress exists
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:config plugins folder does not exist, set to default index.js
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:scaffold scaffolded files ["cypress\integration\example_spec.js","cypress\fixtures\example.json","cypress\support\commands.js","cypress\support\index.js","cypress\plugins\index.js"]
Wed, 20 Dec 2017 02:10:02 GMT cypress:server making saved state from C:Usersaarontmpnode_modulescypressdistCypressresourcesapppackagesserver
Wed, 20 Dec 2017 02:10:02 GMT cypress:server for project path C:Usersaarontmpnode_modules.bin
Wed, 20 Dec 2017 02:10:02 GMT cypress:server state path for project C:Usersaarontmpnode_modules.bin
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:appdata path: C:UsersaaronAppDatatmpCypresscyproductionprojects.bin-51b4388fba0de7ac28bff8df9045a210state.json
Wed, 20 Dec 2017 02:10:02 GMT cypress:server full state path C:UsersaaronAppDatatmpCypresscyproductionprojects.bin-51b4388fba0de7ac28bff8df9045a210state.json
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:file reading JSON file C:UsersaaronAppDatatmpCypresscyproductionprojects.bin-51b4388fba0de7ac28bff8df9045a210state.json
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:scaffold found 0 files in folder C:Usersaarontmpnode_modules.bincypressintegration
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:scaffold untouched scaffold true modal closed false
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:scaffold plugins folder C:Usersaarontmpnode_modules.bincypressplugins
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:scaffold verify scaffolding in C:Usersaarontmpnode_modules.bincypressplugins
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:scaffold missing folder C:Usersaarontmpnode_modules.bincypressplugins
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:scaffold copying index.js into C:Usersaarontmpnode_modules.bincypressplugins
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:scaffold scaffolded files ["cypress\integration\example_spec.js","cypress\fixtures\example.json","cypress\support\commands.js","cypress\support\index.js","cypress\plugins\index.js"]
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events send error: { Error: EEXIST: file already exists, mkdir 'C:Usersaarontmpnode_modules.bincypress'
    at Error (native)

  cause: 
   { Error: EEXIST: file already exists, mkdir 'C:Usersaarontmpnode_modules.bincypress'
       at Error (native)
   
     errno: -4075,
     code: 'EEXIST',
     syscall: 'mkdir',
     path: 'C:\Users\aaron\tmp\node_modules\.bin\cypress' },
  isOperational: true,
  errno: -4075,
  code: 'EEXIST',
  syscall: 'mkdir',
  path: 'C:\Users\aaron\tmp\node_modules\.bin\cypress' }
Wed, 20 Dec 2017 02:10:02 GMT cypress:server:events sending ipc data { type: 'open:project',
  data: 
   { id: 0.4466535685737474,
     __error: 
      { name: 'Error',
        stack: 'Error: EEXIST: file already exists, mkdir 'C:\Users\aaron\tmp\node_modules\.bin\cypress'n    at Error (native)n',
        message: 'EEXIST: file already exists, mkdir 'C:\Users\aaron\tmp\node_modules\.bin\cypress'',
        cause: [Object],
        isOperational: true,
        errno: -4075,
        code: 'EEXIST',
        syscall: 'mkdir',
        path: 'C:\Users\aaron\tmp\node_modules\.bin\cypress' } } }
Wed, 20 Dec 2017 02:10:03 GMT cypress:server:updater latest version of Cypress is: 1.4.0
Wed, 20 Dec 2017 02:10:03 GMT cypress:server:updater new version of Cypress does not exist
Wed, 20 Dec 2017 02:10:03 GMT cypress:server:events sending ipc data { type: 'updater:check',
  data: { id: 0.786888422730067, data: false } }

Доброго времени суток!
На днях переустановил ОС Windows 10. Теперь заново ставлю все необходимое для работы. Поставил Node.js, npm, git. Вот дошло дело до bower, установка прошла успешно:

C:UsersAntoxaVolkovAppDataRoamingnpmbower -> C:UsersAntoxaVolkovAppDataRoamingnpmnode_modulesbowerbinbower
bower@1.7.9 C:UsersAntoxaVolkovAppDataRoamingnpmnode_modulesbower

Запускаю любую команду bower выдает ошибку:

PS C:UsersAntoxaVolkov> bower -v
C:UsersAntoxaVolkovAppDataRoamingnpmnode_modulesbowerlibnode_modulesmkdirpindex.js:89
                    throw err0;
                    ^

Error: EEXIST: file already exists, mkdir 'C:UsersAntoxaVolkov.configconfigstore'

    at Error (native)
    at Object.fs.mkdirSync (fs.js:794:18)
    at Function.sync (C:UsersAntoxaVolkovAppDataRoamingnpmnode_modulesbowerlibnode_modulesmkdirpindex.js:70:13)
    at Object.create.all.get (C:UsersAntoxaVolkovAppDataRoamingnpmnode_modulesbowerlibnode_modulesconfigstoreindex.js:39:13)
    at Object.Configstore (C:UsersAntoxaVolkovAppDataRoamingnpmnode_modulesbowerlibnode_modulesconfigstoreindex.js:28:44)
    at readCachedConfig (C:UsersAntoxaVolkovAppDataRoamingnpmnode_modulesbowerlibconfig.js:19:23)
    at defaultConfig (C:UsersAntoxaVolkovAppDataRoamingnpmnode_modulesbowerlibconfig.js:11:12)
    at Object.<anonymous> (C:UsersAntoxaVolkovAppDataRoamingnpmnode_modulesbowerlibindex.js:16:32)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)

Подскажите пожалуйста, в чем проблема?

You will encounter various kinds of errors while developing Node.js
applications, but most can be avoided or easily mitigated with the right coding
practices. However, most of the information to fix these problems are currently
scattered across various GitHub issues and forum posts which could lead to
spending more time than necessary when seeking solutions.

Therefore, we’ve compiled this list of 15 common Node.js errors along with one
or more strategies to follow to fix each one. While this is not a comprehensive
list of all the errors you can encounter when developing Node.js applications,
it should help you understand why some of these common errors occur and feasible
solutions to avoid future recurrence.

🔭 Want to centralize and monitor your Node.js error logs?

Head over to Logtail and start ingesting your logs in 5 minutes.

1. ECONNRESET

ECONNRESET is a common exception that occurs when the TCP connection to
another server is closed abruptly, usually before a response is received. It can
be emitted when you attempt a request through a TCP connection that has already
been closed or when the connection is closed before a response is received
(perhaps in case of a timeout). This exception will usually
look like the following depending on your version of Node.js:

Output

Error: socket hang up
    at connResetException (node:internal/errors:691:14)
    at Socket.socketOnEnd (node:_http_client:466:23)
    at Socket.emit (node:events:532:35)
    at endReadableNT (node:internal/streams/readable:1346:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'ECONNRESET'
}

If this exception occurs when making a request to another server, you should
catch it and decide how to handle it. For example, you can retry the request
immediately, or queue it for later. You can also investigate your timeout
settings if you’d like to wait longer for the request to be
completed.

On the other hand, if it is caused by a client deliberately closing an
unfulfilled request to your server, then you don’t need to do anything except
end the connection (res.end()), and stop any operations performed in
generating a response. You can detect if a client socket was destroyed through
the following:

app.get("/", (req, res) => {
  // listen for the 'close' event on the request
  req.on("close", () => {
    console.log("closed connection");
  });

  console.log(res.socket.destroyed); // true if socket is closed
});

2. ENOTFOUND

The ENOTFOUND exception occurs in Node.js when a connection cannot be
established to some host due to a DNS error. This usually occurs due to an
incorrect host value, or when localhost is not mapped correctly to
127.0.0.1. It can also occur when a domain goes down or no longer exists.
Here’s an example of how the error often appears in the Node.js console:

Output

Error: getaddrinfo ENOTFOUND http://localhost
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'http://localhost'
}

If you get this error in your Node.js application or while running a script, you
can try the following strategies to fix it:

Check the domain name

First, ensure that you didn’t make a typo while entering the domain name. You
can also use a tool like DNS Checker to confirm that
the domain is resolving successfully in your location or region.

Check the host value

If you’re using http.request() or https.request() methods from the standard
library, ensure that the host value in the options object contains only the
domain name or IP address of the server. It shouldn’t contain the protocol,
port, or request path (use the protocol, port, and path properties for
those values respectively).

// don't do this
const options = {
  host: 'http://example.com/path/to/resource',
};

// do this instead
const options = {
  host: 'example.com',
  path: '/path/to/resource',
};

http.request(options, (res) => {});

Check your localhost mapping

If you’re trying to connect to localhost, and the ENOTFOUND error is thrown,
it may mean that the localhost is missing in your hosts file. On Linux and
macOS, ensure that your /etc/hosts file contains the following entry:

You may need to flush your DNS cache afterward:

sudo killall -HUP mDNSResponder # macOS

On Linux, clearing the DNS cache depends on the distribution and caching service
in use. Therefore, do investigate the appropriate command to run on your system.

3. ETIMEDOUT

The ETIMEDOUT error is thrown by the Node.js runtime when a connection or HTTP
request is not closed properly after some time. You might encounter this error
from time to time if you configured a timeout on your
outgoing HTTP requests. The general solution to this issue is to catch the error
and repeat the request, preferably using an
exponential backoff
strategy so that a waiting period is added between subsequent retries until the
request eventually succeeds, or the maximum amount of retries is reached. If you
encounter this error frequently, try to investigate your request timeout
settings and choose a more appropriate value for the endpoint
if possible.

4. ECONNREFUSED

The ECONNREFUSED error is produced when a request is made to an endpoint but a
connection could not be established because the specified address wasn’t
reachable. This is usually caused by an inactive target service. For example,
the error below resulted from attempting to connect to http://localhost:8000
when no program is listening at that endpoint.

Error: connect ECONNREFUSED 127.0.0.1:8000
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
Emitted 'error' event on ClientRequest instance at:
    at Socket.socketErrorListener (node:_http_client:442:9)
    at Socket.emit (node:events:526:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 8000
}

The fix for this problem is to ensure that the target service is active and
accepting connections at the specified endpoint.

5. ERRADDRINUSE

This error is commonly encountered when starting or restarting a web server. It
indicates that the server is attempting to listen for connections at a port that
is already occupied by some other application.

Error: listen EADDRINUSE: address already in use :::3001
    at Server.setupListenHandle [as _listen2] (node:net:1330:16)
    at listenInCluster (node:net:1378:12)
    at Server.listen (node:net:1465:7)
    at Function.listen (/home/ayo/dev/demo/node_modules/express/lib/application.js:618:24)
    at Object.<anonymous> (/home/ayo/dev/demo/main.js:16:18)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1357:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EADDRINUSE',
  errno: -98,
  syscall: 'listen',
  address: '::',
  port: 3001
}

The easiest fix for this error would be to configure your application to listen
on a different port (preferably by updating an environmental variable). However,
if you need that specific port that is in use, you can find out the process ID
of the application using it through the command below:

Output

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node    2902  ayo   19u  IPv6 781904      0t0  TCP *:3001 (LISTEN)

Afterward, kill the process by passing the PID value to the kill command:

After running the command above, the application will be forcefully closed
freeing up the desired port for your intended use.

6. EADDRNOTAVAIL

This error is similar to EADDRINUSE because it results from trying to run a
Node.js server at a specific port. It usually indicates a configuration issue
with your IP address, such as when you try to bind your server to a static IP:

const express = require('express');
const app = express();

const server = app.listen(3000, '192.168.0.101', function () {
  console.log('server listening at port 3000......');
});

Output

Error: listen EADDRNOTAVAIL: address not available 192.168.0.101:3000
    at Server.setupListenHandle [as _listen2] (node:net:1313:21)
    at listenInCluster (node:net:1378:12)
    at doListen (node:net:1516:7)
    at processTicksAndRejections (node:internal/process/task_queues:84:21)
Emitted 'error' event on Server instance at:
    at emitErrorNT (node:net:1357:8)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'EADDRNOTAVAIL',
  errno: -99,
  syscall: 'listen',
  address: '192.168.0.101',
  port: 3000
}

To resolve this issue, ensure that you have the right IP address (it may
sometimes change), or you can bind to any or all IPs by using 0.0.0.0 as shown
below:

var server = app.listen(3000, '0.0.0.0', function () {
  console.log('server listening at port 3000......');
});

7. ECONNABORTED

The ECONNABORTED exception is thrown when an active network connection is
aborted by the server before reading from the request body or writing to the
response body has completed. The example below demonstrates how this problem can
occur in a Node.js program:

const express = require('express');
const app = express();
const path = require('path');

app.get('/', function (req, res, next) {
  res.sendFile(path.join(__dirname, 'new.txt'), null, (err) => {
    console.log(err);
  });
  res.end();
});

const server = app.listen(3000, () => {
  console.log('server listening at port 3001......');
});

Output

Error: Request aborted
    at onaborted (/home/ayo/dev/demo/node_modules/express/lib/response.js:1030:15)
    at Immediate._onImmediate (/home/ayo/dev/demo/node_modules/express/lib/response.js:1072:9)
    at processImmediate (node:internal/timers:466:21) {
  code: 'ECONNABORTED'
}

The problem here is that res.end() was called prematurely before
res.sendFile() has had a chance to complete due to the asynchronous nature of
the method. The solution here is to move res.end() into sendFile()‘s
callback function:

app.get('/', function (req, res, next) {
  res.sendFile(path.join(__dirname, 'new.txt'), null, (err) => {
    console.log(err);
    res.end();
  });
});

8. EHOSTUNREACH

An EHOSTUNREACH exception indicates that a TCP connection failed because the
underlying protocol software found no route to the network or host. It can also
be triggered when traffic is blocked by a firewall or in response to information
received by intermediate gateways or switching nodes. If you encounter this
error, you may need to check your operating system’s routing tables or firewall
setup to fix the problem.

9. EAI_AGAIN

Node.js throws an EAI_AGAIN error when a temporary failure in domain name
resolution occurs. A DNS lookup timeout that usually indicates a problem with
your network connection or your proxy settings. You can get this error when
trying to install an npm package:

Output

npm ERR! code EAI_AGAIN
npm ERR! syscall getaddrinfo
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/nestjs failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org

If you’ve determined that your internet connection is working correctly, then
you should investigate your DNS resolver settings (/etc/resolv.conf) or your
/etc/hosts file to ensure it is set up correctly.

10. ENOENT

This error is a straightforward one. It means «Error No Entity» and is raised
when a specified path (file or directory) does not exist in the filesystem. It
is most commonly encountered when performing an operation with the fs module
or running a script that expects a specific directory structure.

fs.open('non-existent-file.txt', (err, fd) => {
  if (err) {
    console.log(err);
  }
});

Output

[Error: ENOENT: no such file or directory, open 'non-existent-file.txt'] {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'non-existent-file.txt'
}

To fix this error, you either need to create the expected directory structure or
change the path so that the script looks in the correct directory.

11. EISDIR

If you encounter this error, the operation that raised it expected a file
argument but was provided with a directory.

// config is actually a directory
fs.readFile('config', (err, data) => {
  if (err) throw err;
  console.log(data);
});

Output

[Error: EISDIR: illegal operation on a directory, read] {
  errno: -21,
  code: 'EISDIR',
  syscall: 'read'
}

Fixing this error involves correcting the provided path so that it leads to a
file instead.

12. ENOTDIR

This error is the inverse of EISDIR. It means a file argument was supplied
where a directory was expected. To avoid this error, ensure that the provided
path leads to a directory and not a file.

fs.opendir('/etc/passwd', (err, _dir) => {
  if (err) throw err;
});

Output

[Error: ENOTDIR: not a directory, opendir '/etc/passwd'] {
  errno: -20,
  code: 'ENOTDIR',
  syscall: 'opendir',
  path: '/etc/passwd'
}

13. EACCES

The EACCES error is often encountered when trying to access a file in a way
that is forbidden by its access permissions. You may also encounter this error
when you’re trying to install a global NPM package (depending on how you
installed Node.js and npm), or when you try to run a server on a port lower
than 1024.

fs.readFile('/etc/sudoers', (err, data) => {
  if (err) throw err;
  console.log(data);
});

Output

[Error: EACCES: permission denied, open '/etc/sudoers'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: '/etc/sudoers'
}

Essentially, this error indicates that the user executing the script does not
have the required permission to access a resource. A quick fix is to prefix the
script execution command with sudo so that it is executed as root, but this is
a bad idea
for security reasons.

The correct fix for this error is to give the user executing the script the
required permissions to access the resource through the chown command on Linux
in the case of a file or directory.

sudo chown -R $(whoami) /path/to/directory

If you encounter an EACCES error when trying to listen on a port lower than
1024, you can use a higher port and set up port forwarding through iptables.
The following command forwards HTTP traffic going to port 80 to port 8080
(assuming your application is listening on port 8080):

sudo iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

If you encounter EACCES errors when trying to install a global npm package,
it usually means that you installed the Node.js and npm versions found in your
system’s repositories. The recommended course of action is to uninstall those
versions and reinstall them through a Node environment manager like
NVM or Volta.

14. EEXIST

The EEXIST error is another filesystem error that is encountered whenever a
file or directory exists, but the attempted operation requires it not to exist.
For example, you will see this error when you attempt to create a directory that
already exists as shown below:

const fs = require('fs');

fs.mkdirSync('temp', (err) => {
  if (err) throw err;
});

Output

Error: EEXIST: file already exists, mkdir 'temp'
    at Object.mkdirSync (node:fs:1349:3)
    at Object.<anonymous> (/home/ayo/dev/demo/main.js:3:4)
    at Module._compile (node:internal/modules/cjs/loader:1099:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -17,
  syscall: 'mkdir',
  code: 'EEXIST',
  path: 'temp'
}

The solution here is to check if the path exists through fs.existsSync()
before attempting to create it:

const fs = require('fs');

if (!fs.existsSync('temp')) {
  fs.mkdirSync('temp', (err) => {
    if (err) throw err;
  });
}

15. EPERM

The EPERM error may be encountered in various scenarios, usually when
installing an npm package. It indicates that the operation being carried out
could not be completed due to permission issues. This error often indicates that
a write was attempted to a file that is in a read-only state although you may
sometimes encounter an EACCES error instead.

Here are some possible fixes you can try if you run into this problem:

  1. Close all instances of your editor before rerunning the command (maybe some
    files were locked by the editor).
  2. Clean the npm cache with npm cache clean --force.
  3. Close or disable your Anti-virus software if have one.
  4. If you have a development server running, stop it before executing the
    installation command once again.
  5. Use the --force option as in npm install --force.
  6. Remove your node_modules folder with rm -rf node_modules and install them
    once again with npm install.

Conclusion

In this article, we covered 15 of the most common Node.js errors you are likely
to encounter when developing applications or utilizing Node.js-based tools, and
we discussed possible solutions to each one. This by no means an exhaustive list
so ensure to check out the
Node.js errors documentation or the
errno(3) man page for a
more comprehensive listing.

Thanks for reading, and happy coding!

Check Uptime, Ping, Ports, SSL and more.

Get Slack, SMS and phone incident alerts.

Easy on-call duty scheduling.

Create free status page on your domain.

Got an article suggestion?
Let us know

Share on Twitter

Share on Facebook

Share via e-mail

Next article

How to Configure Nginx as a Reverse Proxy for Node.js Applications

Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Post Views: 2,035

Node.js – Create a new directory:

The inbuilt fs module in Node.js helps us to handle file and folders related operations. In the previous tutorial we saw how to create files and edit it using fs module. Here, we will learn how we can create new folders or directory.

fs is included in Node.js as a inbuilt module so we don’t need to install it using npm in our project. We just need to import in using requirefunction.

Creating new directory using fs.mkdir:

const fs = require('fs');

fs.mkdir('./folder1', (err) => {
if (err) {
console.log("error occurred in creating new directory", err);
return;
}

console.log("New directory created successfully");
})

This basic code will create a new directory at the provided path. The callback function will return error if it occurs.

node-js-fs-module-create-directory

As you can see folder1 was created inside the project folder once the code is executed. The problem with this code is, it will return an error if the folder is already present at the specified path with same name.

starting `node ./index.js`
error occurred in creating new directory [Error: EEXIST: file already exists, mkdir ‘D:nodejsFileSystemfolder1’] {
errno: -4075,
code: ‘EEXIST’,
syscall: ‘mkdir’,
path: ‘D:\nodejs\FileSystem\folder1’
}

To avoid this error in creating directory we can use recursive option in our code like below:

const fs = require('fs');

fs.mkdir('./folder1',
{
recursive: true
}, (err) => {
if (err) {
console.log("error occurred in creating new directory", err);
return;
}

console.log("New directory created successfully");
});

fs.mkdir is an asynchronous functions accepting three arguments as below:

  1. Path (<String> | <Buffer> | <URL>) : Use to specify the path of the directory to be created.
  2. Mode ( <object> | <Integer>) : Optional parameter.
    1. recursive (default:false): When directory is already present, the callback gives an error when recursive is false.
    2. mode: Used to specify the permission of the directory. Default is 0o777
  3. callback : callback function. We can use the function to catch any error if occurred (shown in the above example).

Create Parent directory with new folders inside of it:

If you want to create a new directory and sub-folders inside of it, we can specify it by using folder path structure like:

./pDirectory/folder1/childFolder 

This will create childFolder inside of folder1 and folder1 will be created inside pDirectory

Example:

const fs = require('fs');

fs.mkdir('./pDirectory/folder1/childFolder',
{
recursive: true
}, (err) => {
if (err) {
console.log("error occurred in creating new directory", err);
return;
}

console.log("New directory created successfully");
});

node-js-fs-module-create-parent-child-directory-folder

Also see:

React — Error with create-react-app in Windows Environments — «Error: EEXIST: file already exists, mkdir ‘C:UsersXXXXX» — Fix/Solution

I’ve been asked this a more than once — so thought it prudent to document the current recommended workaround for this issue. While it is possible to install react apps globally to work around the error, it is not recommended per https://create-react-app.dev/docs/getting-started/

«If you’ve previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses the latest version.»

Preconditions:

  • The windows user name has spaces in it (e.g. c:UserDavid Klein)

Steps to reproduce error/issue:

  1. User attempts to create react app with npx in a Windows environment:
    npx create-react-app my-app
  2. Error is generated:

Diagnostics:

  1. Seems that the npm cache path will consequently have a space in the path and npm (or more likely create-react-app) can’t handle this.

Solution (until bug is fixed):

  1. Get the current cache path with «npm config get cache»
  2. cd to the c:Users directory and run dir /x to get the short name of that folder (e.g. DAVIDK~1
  3. Once you have the short path, set the npm cache to use that path with the following:
    npm config set cache c:usersdavidk~1AppDataRoamingnpm-cache —global

You should now be free to continue with your react app goodness in Windows:

TFS Version: 14.102.25423.0 (Tfs2015.Update3)

In my build definition when I set the Path argument of the

Publish Build Artifacts step

with

Artifact type: File share

to

VSALMshare

Behind the scene this build step executes a node.js script function which is called recursively, but there is a bug and the function repeats itself over and over again while trying to create the drop folder**. The failing Build agent script is

mkdir.js

and resides below the build agent folder:

agenttasksPublishBuildArtifacts1.0.28node_modulesshelljssrcmkdir.js

Name of the failing function is:

mkdirSyncRecursive

The error msg:

016-07-23T21:22:02.3703397Z shell.js: internal error 2016-07-23T21:22:02.3703397Z RangeError: Maximum call stack size exceeded

—> Stackoverflow When I enter an absolut path like

c:workspacesshare

I get this error:

2016-07-23T21:03:07.5727256Z shell.js: internal error 2016-07-23T21:03:07.5727256Z Error: EEXIST: file already exists, mkdir ‘C:workspacesshare’

Workaround

When I set the drop folder to (escaped network share path):

\\VSALM\share\$(Build.DefinitionName)\$(Build.BuildNumber)

Then the build step succeeds but the files are not dropped under the path of the share. They are dropped here in my case:

C:VSALMshareMyBuildDefinition20160723.7drop

I don’t know why it doesn’t work with my share set to:

C:workspacesshare

but it works when I create a network share in

C:dropshare

and set the drop folder path in my build definition like this (escaped):

\\drop\share\$(Build.DefinitionName)\$(Build.BuildNumber)

Question: Someone knows how to fix this mkdir.js script?


Jovica

  • Edited by

    Sunday, July 24, 2016 12:18 PM

Понравилась статья? Поделить с друзьями:
  • Error editing value regedit
  • Error ecu rejected ews
  • Error ecu conditions not correct or request sequence error
  • Error econnrefused connect econnrefused
  • Error ec21 2f53