unable connecting to svn using the svn-spawn node module - node.js

I was actually checking on connecting to svn repository from javascript using some wrapper, but was unable to find any such js wrapper. So I found this svn-spawn node module which lets us to connect to the svn repo. But I think I am doing something wrong, not sure where and what. Need some pointers on how to go about resolving the error:
the code :
var Client = require('svn-spawn');
var client = new Client({
cwd: 'http://support.googlecode.com/svn/trunk/'
});
client.cmd(['checkout'], function(err, data) {
if(!err){
console.log('subcommand done' + data);
}else{
console.log('the erro is '+ err);
}
});
the erro that I am getting:
the erro is Error: spawn ENOENT
chdir(): No such file or directory
the erro is Error: chdir(): No such file or directory

The cwd argument is not a URL to the remote repository. Rather, it's a local directory name, when you wish your "current directory" to be, as if you invoked svn from there. Presumably the directory containing .svn.

Related

Why I am not able to push a config file into logstash path using Nodejs ? The below is my code for pushing a file from localserver to logstash server

I am first downloading a config file locally then I have to push that file into logstash server in the path - /etc/logstash/conf.d
const deployLogstash = function(req , res , next){
clientscp.scp('./config-files/15287774.conf', {
host: '172.30.74.250',
port:5000,
username: 'ubuntu',
path: 'root#vm2:/etc/logstash/conf.d/newconfig.conf'
}, function(err,success) {
if(err){
console.log("files failed to upload in remote server"+err);
}
else{
console.log("files uploaded to remote server")
}
});
}
And this is the console.log
serverError: connect ECONNREFUSED 172.30.74.250:5000
Is there any way I could transfer config files to that path?Please help me!
Adding to what #leandrojmp has already mentioned
The URI parameter you're using is of elasticsearch i.e. <hostname>:9200(elasticsearch's port) which meant for sending the contents of a files over elasticsearch indexes as events(termed as documents in Elastic-stack's terminology) But based on the information you've provided, I assume you're trying to upload a config file to your logstash's server directory.
You might wanna read about multer for uploading Files to remote server using multer-sftp, scp, ssh together as mentioned here in this link

Error when trying to locate a json file, node (discord.js)

I'm getting an error when I try to find a file from my folder,
internal/modules/cjs/loader.js:969
throw err;
^
Error: Cannot find module 'badwords.json'
Here is the current code.
client.on("message", message => {
const badwords = require('badwords.json');
I can assure the file is in the same folder, people say it's a problem with my directory, I'm not too sure how to sort this out.
Thanks!

ENOENT error when using fs.writeFile

Trying to write to a file using fs.writeFile into a sibling directory. This works fine when using Sitemap.xml into the same directory, but not with the relative path. The public directory exists and it gives the same error whether or not Sitemap.xml exists.
Relevant dir structure:
/public
Sitemap.xml
app files
/create-sitemap
index.js - file containing code below
app.js
fs.write('../public/Sitemap.xml', data.toString(), function(err) {
if (err) throw err;
console.log("Wrote sitemap to XML");
});
Toms-MacBook-Pro:moviehunter tomchambers$ node create-sitemap/index.js
/Users/tomchambers/projects/project/create-sitemap/index.js:88
if (err) throw err;
^
Error: ENOENT, open '../public/Sitemap.xml'
When you use relative paths in node, they're related to the node process. So, if you run your script like node create-sitemap/index.js from the /Users/tomchambers/projects/project/ directory, it'll look for the /Users/tomchambers/projects/public/Sitemap.xml file, which doesn't exist.
In your case, you could use the __dirname global variable, that returns, as the docs say:
The name of the directory that the currently executing script resides in.
So your code should looks like this:
var path = require('path');
fs.write(path.join(__dirname, '../public/Sitemap.xml'), data.toString(), function(err) {
if (err) throw err;
console.log("Wrote sitemap to XML");
});
For me the problem was that the given filename contained unallowed characters on Windows.
Specifically, I tried adding a timestamp to the name e.g. 10:23:11 and the : were not allowed which caused this error.

Err. ENOENT when renaming a file in node.js

I'm trying to upload a file in my node/express app, but everytime I've got the ENOENT error when renaming the file. My code is that:
var tmp_path = req.files.file.path;
fs.rename(tmp_path, target_path, function (err) {
if(err) throw err;
...
});
where target_path will be the destination path. If I do:
console.log('exists ' + fs.existsSync(tmp_path));
then my server logs:
exists true
Also, listing the contents of tmp directory shows that the file is there. What's the problem?
FS methods like fs.rename which create, move or rename files expect that any directories in the path already exist. When they do not, you'll get an ENOENT. Since very often what you mean is "make this file -- and any directories in the path I specify for it" you may want to consider using an NPM library that abstracts access to fs with methods that take care of such things.
There are quite a few options. For example fs-extra is one of the better-tested libraries. Using fs-extra you can use ensureDir in that operation to make the directory structure first if it does not yet exist.

How to upload file using easy-ftp in node?

I am trying to upload a file into my hosting server using node and easy-ftp.
I try with the following code:
var EasyFtp = require ("easy-ftp");
var ftp = new EasyFtp();
var config = {
host:'homexxxxx.1and1-data.host',
type:'SFTP',
port:'22',
username:'u90xxxx',
password:"mypass"
};
ftp.connect(config);
ftp.upload("/test/test.txt", "/test.txt", function(err){
if (err) throw err;
ftp.close();
});
No error message but no file uploaded
I tried the same using promises
const EasyFTP = require('easy-ftp-extra')
const ftp = new EasyFTP()
const config = {
host:'homexxxxx.1and1-data.host',
type:'SFTP',
port:'22',
username:'u90xxxx',
password:"mypass"
};
ftp.connect(config);
ftp.upload('/test.txt', '/test.txt')
.then(console.log)
.catch(console.error)
ftp.upload()
The same issued. No file is uploaded. No error in node console.
The config is the same used in filezilla to transfer files. SFTP protocol. Everything working well with filezilla.
What I am doing wrong?
Looks like you may have a path problem over here.
"/test/test.txt"
The path specified will try to take file from root folder like "c:\test\test.txt".
Assuming you want the file to be taken from your project folder try this path:
"./test/test.txt"
Other things in your code are precisely the same as in mine and mine works.
For me, it was just silently failing, and intelli-sense was not available.
npm remove easy-ftp
npm install easy-ftp
npm audit fix --force until no more vulnerabilities
Afterwards, intelli-sense was available and it started working.

Resources