0

like so

► add language identifier to highlight code ```python def function(foo): print(foo) 

► put returns between paragraphs

► for linebreak add 2 spaces at end

italic or bold

► indent code by 4 spaces

► backtick escapes like _so_

► quote by placing > at start of line

► to make links (use https whenever possible) https://example.com example example

0

3 Answers 3

1
var fs = require('fs-extra'); var request = require('request'); fs.ensureDir('css'); request('http://agar.io/css/master.css').pipe(fs.createWriteStream('master.css')); fs.move('master.css', 'css/master.css', function (err) { if (err) console.error(err); }); 
Sign up to request clarification or add additional context in comments.

3 Comments

Do not forget to remove (fs.unlink) your css/master.css on rerun.
This works, just tested it. Seems to be an issue related to omitting the callback, which you should have to log errors and help yourself anyways :)
@udidu 's answer is more correct and works with no errors: request is async, so you need to wait for end before move. Anyway, you can move to any name like this: fs.move('master.css', 'css/NEWNAME.css', function (err) { if (err) console.error(err); });
1

You need to wait until the pipe ends to write into the stream before moving the file around.

You can try this:

var fs = require('fs-extra') // This imports the fs-extra dependency var request = require('request') // This imports the request dependency fs.ensureDirSync('css') // This creates a folder called css var stream = request('http://agar.io/css/master.css').pipe(fs.createWriteStream('master.css')) // This downloads the master.css file stream.on('end', function() { fs.move('master.css', 'css') });

Comments

0

Try fs.move('master.css', 'css/master.css')

Comments