I'm trying to clone a Git repository that resides on my local drive into a new folder. So far, I've tried several modules, from which creationix/js-git seemed to be the most promising one.
The code to fetch I use is:
var source = '...',
target = '...';
var remoteRepository = git.remote('file://' + source),
localRepository = git.repo(target);
var options = {
onProgress: function (progress) {
console.log(progress);
}
};
localRepository.fetch(remoteRepository, options, function (err) {
if (err) { throw err; }
console.log('Done');
});
Unfortunately, this does not work, as js-git complains about an unknown URL format, which relates to the file:// protocol being used. The same error appears when I remove the file:// portion.
I also tried to change git.remote to git.repo (as it's not an actual remote), but then I get:
TypeError: Object #<Object> has no method 'discover'
So, apparently js-git does not support fetching from local repositories (or I was not able to find out how to do it).
Does anyone…
…either know how to solve this using js-git,
or can suggest a viable alternative?
Any help is appreciated :-)
Related
I am trying to create a new JSON file. Whenever I try to use the writeFile function, it just says there is no such directory open.
This is the code I've tried.
fs.writeFile('./UserData/' + msg.author + ".json", JSON.stringify({firstSplitContent: firstSplit,secondSplitContent: secondSplit,thirdSplitContent: thirdSplit,fourthSplitContent: fourthSplit,fifthSplitContent: fifthSplit},null,4), err => {
if(err) throw err;
console.log("File is created successfully.")
});
Error: ENOENT: no such file or directory, open './UserData/<#301910353967710208>.json'
help would be appreciated. Yes I know that windows wont use those special characters. I switched it to author.id to remove.
fs.writeFile won't create any directories that don't already exist.
I suspect that the directory in your path, UserData, doesn't exist, which is why you are getting that error.
Otherwise, your path may be wrong. Since you are using a relative path, the code will look for the UserData folder in the working directory, ie. where the code is currently executing.
If the path is correct, try creating it first:
if(!fs.existsSync('./UserData') {
fs.mkdirSync('./UserData')
}
Or, you could use a package such as fs-extra that gives you the capability of creating any folders in the path that don't already exist.
This is probably the most relevant function to you, if you want to use fs-extra:
https://github.com/jprichardson/node-fs-extra/blob/master/docs/outputJson.md
You should follow the answer of Willianm but just one thing I noticed: You are trying to use msg.author in your file name, but that's an object (a really big object), you might want to consider changing it to message.author.id
I've recently started to work on NodeJS, and in particular the knex module to query and insert into databases from the browser.
I've tested my code on my own computer, which worked. For the browser, however, I needed to use the module browserify to transform my code in the right manner (into a bundle.js file).
But, when I load the file in the browser, it gives me an error stating the following:
bundle.js:1 Uncaught Error: Cannot find module './dialects/mysql/index.js'
In the coding, the error gets thrown after this part:
var Dialect;
if (arguments.length === 0 || !config.client && !config.dialect) {
Dialect = makeClient(Client);
} else {
var clientName = config.client || config.dialect;
Dialect = makeClient(require("./dialects/" + (aliases[clientName] ||clientName) + "/index"));
}
After this, and error is thrown, while the file does actually exist in the path that is specified. furthermore, lines of code before this, like for example:
var Readable = require('./_stream_readable');
var Writable = require('./_stream_writable');
Do actually work fine, so I guess it cannot be that the function is searching in the wrong directory. I'm running out of new ideas on how to possibly fix this, so I'm hoping that someone knows a bit more about this.
I am trying to save a simple file to a directory other then my root directory, but it seems to error out when using a variable instead of a direct string.Has anyone tried using a variable or see if i am missing something.
Thanks
var procedures = "SomeString";
var moveTo = "C:/SavedFiles";
//////////////////
fs.writeFile(moveTo ,procedures, function (err) {
if (err) {
return console.log(err);
}
console.log("The file was saved!");
});`
Am I correct that "C:/SavedFiles" is a directory? Is so, then specify a file to write to like:
var moveTo = "C:/SavedFiles/myfile.txt";
// keep the rest the same
Not sure about the slashes though, not running Windows ATM.
So it looks like my error was due to a rouge loop above my code not posted. Sorry i didn't post the rest of the code
I am trying to read the metadata tags from an mp4 file into my javascript using the node module mp4js. I followed the model provided on that page but with some issue.
I tried the following:
var mp4 = require('mp4js');
mp4({ file: 'small.mp4', type: 'local' }, function (err, tags) {
// tags now contains your MP4 tags
console.log('Tags: ' + tags)
$scope.mp4Tags = tags;
});
and I was met with Uncaught TypeError: Cannot read property 'join' of undefined
Does anyone know what I'm missing here? Could it be that the mp4 doesn't have any tags? I just googled "sample mp4" and downloaded something. It's my first time trying this module and I am pretty new to node.
I'm also open to other suggestions for reading mp4 metadata.
Thank you very much for your time and let me know if you need any additional from me.
EDIT 8.26.2015
Following Brad's suggestion, I tried the following code to read metadata from an mp4:
var child_process = require('child_process');
ls = child_process.spawn('ffmpeg/bin/ffprobe.exe', ['-print_format', 'json', 'out.mp4']);
ls.stdout.on('data', function (data) {
console.log('stdout: ' + data);
$scope.mp4data = data;
});
I created mp4.out by following this example for adding a title meta tag using ffmpeg from the command line. Here is a screenshot of my output. Here is the command I entered:
ffmpeg -i in.avi -metadata title="my title" out.flv
After running my app with the code above, the value stored in $scope.mp4data is a Native Buffer that looks like this. All I see are some numbers, but no metadata tags. How can I view the metadata such as the title that I set using the command above? Am I missing something in the arguments? Or maybe I should be looking at something other than data?
Thanks for the help. I may just post this as a new question since the focus has shifted.
EDIT: Solution
Here's where I landed thanks to Brad's help:
$scope.mp4data = "";
ls.stdout.on('data', function (data) {
$scope.mp4data = $scope.mp4data + data.toString();
});
ls.stdout.on('end', function (data) {
$scope.mp4data = JSON.parse($scope.mp4data);
});
works great for reading metadata from my mp4! Thanks Brad!
I recommend using FFprobe (from the FFmpeg project) to do this instead. It supports many containers, including MP4.
You can use ffprobe -print_format json to have it output JSON data that you can parse inside your Node.js app.
Some examples here: https://stackoverflow.com/a/8191228/362536
I'm trying to migrate a node project to run in the browser. The project (nevermind the reason for the moment) writes to a temporary file, using temp with code similar to this:
var temp = require('temp');
var fs = require('fs');
temp.open('helloworld.txt', function (err, info) {
if (err) {
console.log('Failed to open a temp file:', err);
return;
}
console.log('temp: ', info.path);
fs.writeFile(info.path, 'Hello World!', function (err2) {
if (err2) {
console.log('Failed to write to a temp file:', err2);
return;
}
});
});
When running the browserified code I get the following error:
Uncaught TypeError: undefined is not a function
for the following line:
fs.open(filePath, RDWR_EXCL, 0600, function(err, fd) {
which is called by temp.open.
I'm very much aware you cannot write files using plain ol' javascript in the browser, but I was wondering if browserify have some replacement for that, especially since we're talking about a temp file.
I found browserify-fs, and tried:
browserify -r fs:browserify-fs my-example.js -o bfied.js
but I get the exact same error. I tried to replace require('fs') with require('browserify-fs') but this resulted in a similar error as well (I of course installed browserify-fs module..)
Any suggested solution would be appreciated :) If this type of migration is not possible, I'd also be glad to know..
Thanks!
I stumbled across this post as I think I was trying to do pretty much the exact same thing as you. I am not sure where you got to with this, but I found that when using browserify-fs, you cannot access files outside the sandboxed state of the browser.
So when trying...
var fs = require('broserify-fs);
fs.read('hello.txt', 'utf8' ....
I got the same error as you, but when doing this...
fs.mkdir('/home', function() {
fs.writeFile('/home/hello-world.txt', 'Hello world!\n', function() {
fs.readFile('/home/hello-world.txt', 'utf-8', function(err, data) {
console.log(data);
});
});
});
Everything worked fine (using just temporary files I think).
I am super new to this so I'm not sure what the best approach is. I imagine you either want to run a Node.js server locally and issue ajax commands to it to perform read/write operations, or investigate the HTML5 file system stuff - this looks like a good article - http://www.html5rocks.com/en/tutorials/file/dndfiles/
Hope that's some help (sorry you've had to wait 2 months for an answer ;) It was serendipitous I happened to stumble across your question and my heart sank when there were no answers)
Tom