diff --git a/examples/downloadDir.js b/examples/downloadDir.js index eba72f6..e22a7ac 100644 --- a/examples/downloadDir.js +++ b/examples/downloadDir.js @@ -3,11 +3,10 @@ // Example of using the downloadDir() method to download a directory // from a remote SFTP server to a local directory -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import SftpClient from '../src/index.js'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const SftpClient = require('../src/index.js'); const config = { host: process.env.SFTP_SERVER, diff --git a/examples/exists.js b/examples/exists.js index 272d52d..1fa0628 100644 --- a/examples/exists.js +++ b/examples/exists.js @@ -2,11 +2,10 @@ // sample use of exists() to test for remote dir/file existance -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import Client from '../src/index.js'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const Client = require('../src/index.js'); const config = { host: process.env.SFTP_SERVER, diff --git a/examples/fastget.js b/examples/fastget.js index a789ba6..b1ad35c 100644 --- a/examples/fastget.js +++ b/examples/fastget.js @@ -1,10 +1,7 @@ -'use strict'; - -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import SftpClient from '../src/index.js'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const SftpClient = require('../src/index.js'); const config = { host: process.env.SFTP_SERVER, diff --git a/examples/fastput.js b/examples/fastput.js index 0050d2c..2e6b527 100644 --- a/examples/fastput.js +++ b/examples/fastput.js @@ -1,11 +1,7 @@ -'use strict'; - -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import { join } from 'node:path'; -import SftpClient from '../src/index.js'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const SftpClient = require('../src/index.js'); const config = { host: process.env.SFTP_SERVER, diff --git a/examples/get-stream.js b/examples/get-stream.js index 1d30dd9..24584ab 100644 --- a/examples/get-stream.js +++ b/examples/get-stream.js @@ -4,12 +4,11 @@ // to retrieve the file and then uses a pass through stream to pipe // the contents to standard out. -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import Client from '../src/index.js'; -import { PassThrough } from 'node:stream'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const Client = require('../src/index.js'); +const { PassThrough } = require('node:stream'); const config = { host: process.env.SFTP_SERVER, diff --git a/examples/get-writeable.js b/examples/get-writeable.js index bbf9f70..505363d 100644 --- a/examples/get-writeable.js +++ b/examples/get-writeable.js @@ -3,11 +3,12 @@ // Example of using a writeable with get to retrieve a file. // This code will read the remote file, convert all characters to upper case // and then save it to a local file - -import Client from '../src/index.js'; -import { join } from 'node:path'; -import { createWriteStream } from 'node:fs'; -import through from 'through2'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const Client = require('../src/index.js'); +const { createWriteStream } = require('node:fs'); +const through = require('through2'); const config = { host: 'arch-vbox', diff --git a/examples/large-buffer.js b/examples/large-buffer.js index 8b708ce..8efdbb9 100644 --- a/examples/large-buffer.js +++ b/examples/large-buffer.js @@ -4,12 +4,11 @@ // Note that in most cases you are far better off using a stream rather than // a buffer. -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import { readFileSync } from 'node:fs'; -import Client from '../src/index.js'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const { readFileSync } = require('node:fs'); +const Client = require('../src/index.js'); const config = { host: process.env.SFTP_SERVER, diff --git a/examples/list.js b/examples/list.js index 31801ed..a0534f8 100644 --- a/examples/list.js +++ b/examples/list.js @@ -3,10 +3,9 @@ // Simple script which just display a directory listing for a // remote sftp directory specified on the command line -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); const Client = require('../src/index.js'); const config = { diff --git a/examples/listing-with-key.js b/examples/listing-with-key.js index b2b69d8..71b4a62 100644 --- a/examples/listing-with-key.js +++ b/examples/listing-with-key.js @@ -3,12 +3,11 @@ // Simple script to produce a directory listing of a remote sftp directory // with error checking and using a key and passphrase to control access. -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import { readFileSync } from 'fs'; -import Client from '../src/index.js'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const { readFileSync } = require('node:fs'); +const Client = require('../src/index.js'); const config = { host: process.env.SFTP_SERVER, diff --git a/examples/mkdir.js b/examples/mkdir.js index 4b07aeb..fb3ac73 100644 --- a/examples/mkdir.js +++ b/examples/mkdir.js @@ -3,11 +3,10 @@ // sample mkdir use // Usage: node ./mkdir.js [debug] -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import Client from '../src/index.js'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const Client = require('../src/index.js'); const config = { host: process.env.SFTP_SERVER, diff --git a/examples/multiple-get.js b/examples/multiple-get.js index d661911..8e653f9 100644 --- a/examples/multiple-get.js +++ b/examples/multiple-get.js @@ -1,11 +1,9 @@ 'use strict'; -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import { join } from 'path'; -import Client from '../src/index.js'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const Client = require('../src/index.js'); const config = { host: process.env.SFTP_SERVER, diff --git a/examples/multiple-get2.js b/examples/multiple-get2.js index 0171465..144b094 100644 --- a/examples/multiple-get2.js +++ b/examples/multiple-get2.js @@ -1,11 +1,9 @@ 'use strict'; -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import { join } from 'path'; -import Client from '../src/index.js'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const Client = require('../src/index.js'); const config = { host: process.env.SFTP_SERVER, diff --git a/examples/realpath.js b/examples/realpath.js index fad7cbd..5ac6b83 100755 --- a/examples/realpath.js +++ b/examples/realpath.js @@ -3,11 +3,10 @@ // The 'realpath' functionality varies across sftp servers, // especdially with respect to handling '.' and '..' -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import Client from '../src/index.js'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const Client = require('../src/index.js'); const client = new Client(); const targetPath = process.argv[2]; diff --git a/examples/sftp-config-example.js b/examples/sftp-config-example.js index 632ece5..1343b85 100644 --- a/examples/sftp-config-example.js +++ b/examples/sftp-config-example.js @@ -1,5 +1,5 @@ -import { readFileSync } from 'node:fs'; -import Client from '../src/index.js'; +const { readFileSync } = requ8ire('node:fs'); +const Client = require('../src/index.js'); const keyFile = `${process.env.HOMfe}/.ssh/id_ed25519.pub`; diff --git a/examples/stream-put.js b/examples/stream-put.js index 90fcaa8..af0238b 100644 --- a/examples/stream-put.js +++ b/examples/stream-put.js @@ -7,12 +7,11 @@ * passing the readStream to put(). You could just pass the buffer directly. * We are using the ReadStream just for demonstration purposes */ -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import { Readable } from 'node:stream'; -import Client from '../src/index'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const { Readable } = require('node:stream'); +const Client = require('../src/index'); const config = { host: process.env.SFTP_SERVER, diff --git a/examples/uploadDir.js b/examples/uploadDir.js index 819be0c..7372a13 100644 --- a/examples/uploadDir.js +++ b/examples/uploadDir.js @@ -3,12 +3,10 @@ // Example of using the uploadDir() method to upload a directory // to a remote SFTP server -const dotenvPath = new URL('../.env', import.meta.url); -import dotenv from 'dotenv'; -dotenv.config({ path: dotenvPath }); - -import { join } from 'path'; -import SftpClient from '../src/index.js'; +const { join } = require('node:path'); +const dotenvPath = join(__dirname, '..', '.env'); +require('dotenv').config({ path: dotenvPath }); +const SftpClient = require('../src/index.js'); const config = { host: process.env.SFTP_SERVER,