Show file content as per user input

I’m learning Node.js and have just stumbled upon the File system module.

Now, I can show the content of a file on my PC by providing a path in my .js file.

But say if I wanted to type in the path to a file on my system in an HTML form and its content would be shown to me upon clicking a submit button; I know I can’t use any event listeners in this case because it’s Node.

Is it possible? Or do I need to use something like Express.js?

Yup. You’ll need middleware to connect the server to the client.

If you’re planning to do something like this, you may want to look into building an Electron app, since the client code will need to run on your computer anyway.

1 Like

Seems like a nice idea for a little project!

But would I still need something like Express.js if I were to build an Electron app?

You probably wouldn’t use Express. I believe that Electron has it’s own routing handling. The pieces still need to be “glued” together, but you don’t need to do it via the same methods.

1 Like