by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 21 2018 17:11
    @MadLittleMods banned @OmarAlmaqtri
  • Jun 05 2018 23:13
    @MadLittleMods banned @LWSS
  • May 25 2018 16:50
    @MadLittleMods banned @TheRedstoneTaco
Norman
@nkoehring
@Abdul___Says_twitter thanks.
@jayeshguru oh I thought it is move, oops. I should have been the one to check documentation :D
That looks like this should work, but you need to make sure to use a callback (or renameSync) and make sure the oldPath really exists
Jayesh Guru
@jayeshguru
@nkoehring , Why I am getting the error though? rename is not a function
Stephen James
@sjames1958gm
@jayeshguru Show more of the code. fs.rename should be a function.
Jayesh Guru
@jayeshguru
@sjames1958gm below is the code
const fs = require('fs')
        function getFileName() {  
                var randomString = getRandomStringFromTimeStamps();
                fs.rename('../fixtures/' + UPLOAD_CSV_CONSTANTS.UPLOAD_CSV_NAME + '.csv', '../fixtures/' + UPLOAD_CSV_CONSTANTS.UPLOAD_CSV_NAME + randomString + 
               '.csv', (err) => {
               if (err) throw err;
               console.log('Rename complete!');
    });
Norman
@nkoehring
it is not exactly related to your problem, but indentation helps A LOT with understanding what's going on.
Norman
@nkoehring
const fs = require('fs');
const csvName = `../fixtures/${UPLOAD_CSV_CONSTANTS.UPLOAD_CSV_NAME}`;

function getFileName() {
  let randomString = getRandomStringFromTimeStamps();
  fs.rename(`${csvName}.csv`, `${csvName}${randomString}.csv`, err => {
      if (err) throw err;
      console.log('Rename complete!');
  });
}

So that is readable, I guess. Now lets go for the potential debugging options:

Did you try to see what you get from console.log(fs) and console.log(fs.rename) maybe also console.log(typeof fs) and console.log(typeof fs.rename) respectively.

Jayesh Guru
@jayeshguru
@nkoehring So I am getting typeof fs as an object but both fs.rename and typeof fs.rename returns undefined
Norman
@nkoehring
maybe your node version is the issue? which one is it?
> const fs = require("fs")
undefined
> fs.renameSync
[Function: renameSync]
> fs.rename
[Function: rename]
For me it works using Node 12
Jayesh Guru
@jayeshguru
Mine is node14
I think the issue could be Cypress where I am trying to do this
it seems Cypress does not allow to access fs inside test
Xtronoid
@Xtronoid_twitter
someone using JQUERY?
suddenly my vscode started to strikethrough the jQuery resize method... and it´s not deprecated... im confused
Shekhar Ramola
@shekharramola
I have an array of objects which I want to sort alphabetically( ascending and descending) but there is one catch, i.e., one element on that array which I always want in put in top. what will be the most efficient way todo that?
Norman
@nkoehring
@jayeshguru that is possible and would make sense
It is also not a good idea to do actual fs changes inside a test suite. You should instead mock the fs functions and check the calls, therefore trusting the underlying implementation.
@shekharramola is that some kind of study assignment?
Xtronoid
@Xtronoid_twitter
wait, i dont need jquery
the worst point is, yes i can create my eventemitter
but what´s the best/fast modern shortcurt for listening an existing object? like body?
Norman
@nkoehring
nobody really needs jquery
What is it that you want to achieve @Xtronoid_twitter
Xtronoid
@Xtronoid_twitter
oh i managed creating a static nodejs event bus
and switching listeners of some loaders for methods with already got callback
some selectors was mess, just migrated to css
and probably some body event, i will tunnel via the static event bus
i think the only drawback is the famous getElementByID
but cmon... it´s just some consts :D
ezekel
@ezekel
Need help for the pattern input
pattern="^(1200|1500).*" my problem is I want to check also if the length is 10
Sam Tuke
@samtuke
Noob question: Copying the xpath to an element in Chrome inspector gives eg "/html/body/div[2]/div[1]/ul/li[7]", but pasting that into the Chrome console says "is not a valid selector" (eg $$("/html/body/div[2]/div[1]/ul/li[7]"). Why doesn't Chrome recognise it's own Xpaths?
Norman
@nkoehring
@ezekel that's not how patterns work. They work on a single code point (read: character) basis. So to check if it starts with 1200 or 1500 you'd rather use ^1[25]00.{6}$ (that also checks for "6 more codepoints of any kind")
In case you also need that match group: ^(1[25]00).{6}$
(Disclaimer: I wrote this out of my head without testing or anything. Please check https://regexr.com/ or similar in case it doesn't work as expected.)
@samtuke not sure if this is actually a noob question. I personally have no idea, sorry.
2 replies
Divine C
@Divine1
this is not related to javascript but i'm posting it here as some folks would be aware of this. any idea on what is /dev/null related to ? i often see comments on articles like thistail -f /dev/null
Norman
@nkoehring
@Divine1 it is a unix (linux/bsd/macos) device file that throws everything you write to it into the aether
it is basically the shredder
the opposite of it is /dev/zero which produces zeros. so whenever you read that file you get zeros. Can be used to fill/overwrite/reset something, eg dd if=/dev/zero of=/path/to/file bs=512 would overwrite /path/to/file with zeros in 512 byte blocks.
Divine C
@Divine1
@nkoehring thankyou, when should i use this? in which scenarios will this be helpful for me?
Stephen James
@sjames1958gm
I use /dev/null when using find and grep together
find . -type f -exec grep “string” {} /dev/null \;
Without that grep won’t show the file name of matches
Rohit Yadav
@rohyadav

anyone help me about :- reverse string
reverseString("29-02-2018");
// output :

"2018-02-29"

Norman
@nkoehring
@rohyadav solving student assignments is not our goal here. I'm pretty sure you can find a solution yourself.
Rohit Yadav
@rohyadav
ok sir, i am learning javascript , i am not good at it. thanks for your response :-)
Norman
@nkoehring
If you want, you can tell me your ideas on how to approach the problem and I'm happy to help
Rohit Yadav
@rohyadav

function reverseString(str) {
return str.split("-").reverse().join("-");
}

reverseString("29-02-2018");

@nkoehring thank you for pushing me :-)
Norman
@nkoehring
glad to help