I am trying to load NPM module for SFTP, so i can read the source files from remote server to import into target server
here is my code which i put in “test” tab
// npm SFTP
pm.sendRequest("https://cdn.jsdelivr.net/npm/[email protected]/src/index.min.js", (err, res) => {
//convert the response to text and save it as an environment variable
pm.collectionVariables.set("ssh2-sftp-client_lib", res.text());
// eval will evaluate the JavaScript code and initialize the min.js
eval(pm.collectionVariables.get("ssh2-sftp-client_lib"));
//const Client = require('ssh2-sftp-client');
const config = {
host: 'example.com',
username: 'donald',
password: 'my-secret'
};
const sftp = new Client('example-client');
sftp.connect(config)
.then(() => {
return sftp.cwd();
})
.then(p => {
console.log(`Remote working directory is ${p}`);
return sftp.end();
})
.catch(err => {
console.log(`Error: ${err.message}`); // error message will include 'example-client'
});
})
here the error
Error: Cannot find module ‘ssh2’
My understand is, if i load the npm from CDN, i don’t need to use the “required” keyword. But the error seems it’s caused by NPM can’t install/required the dependency of other modules
Any guru can advices on this? thanks