So I want to chain operations in a group of 3 files… and then another group of 5 files…
I suppose I can use import exports to run functions from one file to another… but!!!
If I export a function from one file… can I still run the file as stand alone??
I am asking because I have been getting some errors when I try to run a file while I am also exporting a function from the same file…
Also… what would it be a good way time the functions so they don’t overlap?.. for example… one function needs to create a file… then I might need to do the import of that file… and then another function needs do something with that same file… so… how do I make sure the reading function isn’t starting before the file creating function is finish?
What are the errors your seeing? When asking for help in all situations, do not talk about errors without giving them.
Generally having stuff in different files doesn’t matter regardless of other contexts, but how you import and use stuff does. JavaScript has multiple ways to import/export stuff between files, and multiple ways to run all with their own different rules.
Also… what would it be a good way time the functions so they don’t overlap?.. for example… one function needs to create a file… then I might need to do the import of that file… and then another function needs do something with that same file… so… how do I make sure the reading function isn’t starting before the file creating function is finish?
Generally doing stuff is either synchronous or asynchronous. If your doing just 1 thing (say creating a file, then doing something else) you could use either approach. However if your using the “async” approach you will need your code to “wait” for the process to be complete before continuing.
What your describing is a “race condition”, where multiple async tasks could “race” and create issues since timings are all of.
I think I need to add the “.js” at the end of the import…
It also just doesn’t export just the function, but all the settings from the file, such as listen in port 3030… AND it fires right away, which is something I don’t want…
If I am gonna chain this together I need to comment and uncomment the ports if I want to run it as a single file or chain… also need to put the import and control it until another function is done…