Skip to content

Adding fileWrite to nodebb code

Solved Configure
16 2 4.1k 1
  • I have a test nodebb (no live users) and I want to see what is / isnt possible, in regard to owners accessing passwords.
    In src/password.js I added
    const fs=require(‘fs’)
    and a line to write password to a txt file. It didnt even open a file (even when just writing a text string in simpler test … see screenshot)
    I also added the same to src/user/password.js as I assumed one of these files will be accessed when someone logs in.
    So why was no pasfi.txt file ever created?
    Disclamer, I would not obviously do this on a live forum, but Im curious
    Screenshot_20221010-141223_Termius~2.jpg

    @eveh You’d need to recompile the password.js file for any changes to be picked up. This typically won’t work unless you use ./nodebb build && ./nodebb start. Even then, you may still require a local DEV instance of webpack.

    One other way would be to use one of the existing hooks in NodeBB and create a custom JS function for it.

  • phenomlabundefined phenomlab has marked this topic as solved on
  • @eveh You’d need to recompile the password.js file for any changes to be picked up. This typically won’t work unless you use ./nodebb build && ./nodebb start. Even then, you may still require a local DEV instance of webpack.

    One other way would be to use one of the existing hooks in NodeBB and create a custom JS function for it.

    @phenomlab thanks, tried the recompile but still nothing.
    I have it running on a test server (so not locally)
    I tried reading up about hooks but didnt fully understand.
    If I use a non-async file write command would I still need that?
    Can you help me get started with this hook / webpack thing?

  • @phenomlab thanks, tried the recompile but still nothing.
    I have it running on a test server (so not locally)
    I tried reading up about hooks but didnt fully understand.
    If I use a non-async file write command would I still need that?
    Can you help me get started with this hook / webpack thing?

    @eveh said in Adding fileWrite to nodebb code:

    If I use a non-async file write command would I still need that?

    Yes, because you are changing one of the core files

    @eveh said in Adding fileWrite to nodebb code:

    I tried reading up about hooks but didnt fully understand.

    Did you review this page ?

    https://docs.nodebb.org/development/plugins/hooks/

    @eveh said in Adding fileWrite to nodebb code:

    Can you help me get started with this hook / webpack thing?

    That’s a question probably best asked over on the community forms, as that’s where the devs are located

    https://community.nodebb/org

  • @eveh said in Adding fileWrite to nodebb code:

    If I use a non-async file write command would I still need that?

    Yes, because you are changing one of the core files

    @eveh said in Adding fileWrite to nodebb code:

    I tried reading up about hooks but didnt fully understand.

    Did you review this page ?

    https://docs.nodebb.org/development/plugins/hooks/

    @eveh said in Adding fileWrite to nodebb code:

    Can you help me get started with this hook / webpack thing?

    That’s a question probably best asked over on the community forms, as that’s where the devs are located

    https://community.nodebb/org

    @phenomlab thanks
    But something Im still not getting, Ive coded it to write to a file when that hash function is called, so I dont understand why it needs to be triggered by a hook event?
    Its like when it runs that function how can it not write the file, its not something that needs to be triggered by an action, it should just do it when that function runs?

  • @phenomlab thanks
    But something Im still not getting, Ive coded it to write to a file when that hash function is called, so I dont understand why it needs to be triggered by a hook event?
    Its like when it runs that function how can it not write the file, its not something that needs to be triggered by an action, it should just do it when that function runs?

    @eveh The hook will trigger, but not if you are modifying password.js directly as it will need to be recompiled. To execute the hook, you should use /admin/appearance/customise#custom-js

  • @eveh The hook will trigger, but not if you are modifying password.js directly as it will need to be recompiled. To execute the hook, you should use /admin/appearance/customise#custom-js

    @phenomlab
    Update, the basic file write did work, I found the txt file did have the ‘!o!’ string characters in.
    But the write of password never worked.
    I tried both (file, password…
    And then wondered if password is an object so tried unpacking it as a string, which didnt work)
    See below
    So its the way Im referencing password that might be problem?
    Screenshot_20221010-194743_Termius~2.jpg

  • @phenomlab
    Update, the basic file write did work, I found the txt file did have the ‘!o!’ string characters in.
    But the write of password never worked.
    I tried both (file, password…
    And then wondered if password is an object so tried unpacking it as a string, which didnt work)
    See below
    So its the way Im referencing password that might be problem?
    Screenshot_20221010-194743_Termius~2.jpg

    @eveh does the account you are running the under have permissions to the file storage ?

  • @eveh does the account you are running the under have permissions to the file storage ?

    @phenomlab yes, sure it does as its doimg the first write to the File,
    Just not where I reference password variable

  • @phenomlab yes, sure it does as its doimg the first write to the File,
    Just not where I reference password variable

    @eveh what’s the output if you stop NodeBB and then run it from the console as ./nodebb dev ?

  • @eveh what’s the output if you stop NodeBB and then run it from the console as ./nodebb dev ?

    @phenomlab could that make a difference if the first write is working?

  • @phenomlab could that make a difference if the first write is working?

    @eveh I don’t expect it to make a difference, no, but it should at least provide some debug logging so you can get an idea of why it fails.

  • @eveh I don’t expect it to make a difference, no, but it should at least provide some debug logging so you can get an idea of why it fails.

    @phenomlab i think issue may have been i didnt stop nodebb before i ran it again in dev

  • @phenomlab i think issue may have been i didnt stop nodebb before i ran it again in dev

    @eveh now you know why I said stop NodeBB first 😁

  • @eveh now you know why I said stop NodeBB first 😁

    @phenomlab Narrowed down this issue, its something to do with accessing these variables
    If I write text out like ‘User’ or ‘password’ that goes to the file.
    But when I try these variables or objects (whatever they are) it never works.
    Ive tried writing out User, password, JSON.stringify(password)
    I dont know how to reference what is contained in User or password
    Below screenshot of the plain text that does work!

    Screenshot_20221010-212300_Termius~2.jpg

    I dont know much about these module exports, or what is passed into the parameter

  • @phenomlab Narrowed down this issue, its something to do with accessing these variables
    If I write text out like ‘User’ or ‘password’ that goes to the file.
    But when I try these variables or objects (whatever they are) it never works.
    Ive tried writing out User, password, JSON.stringify(password)
    I dont know how to reference what is contained in User or password
    Below screenshot of the plain text that does work!

    Screenshot_20221010-212300_Termius~2.jpg

    I dont know much about these module exports, or what is passed into the parameter

    @eveh this might be a question for the NodeBB Devs themselves. In all honesty, I’m not entirely sure without having to research this myself.


Did this solution help you?
Did you find the suggested solution useful? Support 💗 Sudonix with a coffee
If your organisation needs deeper expertise around infrastructure, security, or technology leadership, learn more about Phenomlab Ltd. Many of the deeper technical guides behind Sudonix are published there.

Related Topics
  • NodeBB upgrade now cant post

    Solved Bugs nodebb
    5
    2 Votes
    5 Posts
    2k Views
    @Panda yes, for some reason, that is the case. If you need an urgent response, it’s probably better to post here because of the time difference.
  • NodeBB: Consent page

    Solved Configure nodebb consent
    16
    4 Votes
    16 Posts
    5k Views
    @DownPW I still do not see any issues.
  • restarting nodebb on boot

    Unsolved Configure nodebb
    3
    1 Votes
    3 Posts
    2k Views
    @eeeee said in restarting nodebb on boot: can I just run nodebb under nodemon for auto restarts? It’s a better method. Nodemon just looks for file system changes and would effectively die if the server was rebooted meaning you’d have to start it again anyway. Systemd is the defacto standard which is how the operating system interacts in terms of services, scheduled tasks etc.
  • How to fix size of photos & videos NodeBB

    Solved Customisation nodebb nodebb size
    7
    3 Votes
    7 Posts
    2k Views
    @crazycells pleasure. Using percentages makes much more sense in this case. It’s the same argument with px vs pt vs em with fonts, margins, padding, etc., in the sense that em is generally preferred over px and pt https://stackoverflow.com/questions/609517/why-em-instead-of-px
  • Top Ranked Forums

    Chitchat nodebb top ranked
    9
    1
    3 Votes
    9 Posts
    3k Views
    The real issue here is that most people consider forums to be “dead” in the sense that nobody uses them anymore, and social media groups have taken their place. Their once dominant stance in the 90’s and early 00’s will never be experienced again, but having said that, there are a number of forums that did in fact survive the social media onslaught, and still enjoy a large user base. Forums tend to be niche. One that immediately sticks out is Reddit - despite looking like it was designed in the 80s, it still has an enormous user base. Another is Stack Overflow, which needs no introduction. The key to any forum is the content it offers, and the more people whom contribute in terms of posting , the more popular and widely respected it becomes as a reliable source of information. Forums are still intensely popular with gamers, alongside those that offer tips on hacking etc.
  • Post Style View

    Solved Customisation post style sudonix nodebb
    67
    2
    18 Votes
    67 Posts
    27k Views
    @cagatay Just add margin-left on the element like @phenomlab said to you : topic [component="post/parent"] { margin-left: 10px; } [image: 1669191112290-aa08c62b-4223-4cba-8c0f-c73d50474c0d-image.png] Maybe @phenomlab have a better way
  • is "night mode" shifting the forum several pixels up?

    Solved Configure nodebb
    8
    4 Votes
    8 Posts
    2k Views
    @crazycells hmm. Good point. I actually use my own version of the dark mode plugin, so not entirely sure. However, I think the CSS is probably the same. I’m not at my PC currently but can check and advise later.
  • [NodeBB] Creating new user to auto post content

    Solved Customisation
    3
    0 Votes
    3 Posts
    2k Views
    @phenomlab many thanks Mark .