简体   繁体   中英

TypeError: path.join is not a function

The code that I have posted is working if I take AWAY the below function that I have wrapped the code with:

 watcher.on('add', function (path) { });

But if running the below code. I do get this error where path.join is not a function. As seen I want to all the time run the code inside watcher.on when a file has been added. The code does react when I add a file but again I always receive below error. Do I set up the watcher.on code wrong or what causes the error?

File C:\\myproject\\instances\\b53pd4574z8pe9x793go\\New Text Document.txt has been added (node:14360) UnhandledPromiseRejectionWarning: TypeError: path.join is not a function

Complete code:

 'use strict'; const ccxt = require('ccxt'); const fs = require('fs'); const path = require('path'); var chokidar = require('chokidar'); var watcher = chokidar.watch('C:/myproject/instances/b53pd4574z8pe9x793go', { ignored: /^\\./, persistent: true }); var i; const exchangename = "binance"; const exchange = new ccxt.binance({ 'enableRateLimit': false }); watcher.on('add', function (path) { (async () => { console.log('File', path, 'has been added') const start = Date.now() var orderbookPromises = [] var symbols = ['ETH/BTC'] for (i = 0; i < symbols.length; i++) { const symbol = symbols[i] try { let tickerProcessing = new Promise(async (resolve) => { const orderbook = await exchange.fetchOrderBook(symbol, 5) const exchangename2 = exchangename + '#' + symbol.replace("/", "") const dumpFile = path.join(__dirname, 'orderbooks', `${exchangename2}Orderbook.txt`) await fs.promises.writeFile(dumpFile, JSON.stringify(orderbook)) resolve() }) orderbookPromises.push(tickerProcessing) } catch (e) { console.error(e) } } // wait for all of them to execute or fail await Promise.all(orderbookPromises) const end = Date.now() console.log(`Done in ${(end - start) / 1000} seconds`) })() });

I think, it because you send 'path' as a parameter and at the same time, trying to call join() from 'path'. Rename input param in 'function (path)', i think it will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM