stackblitz / core

Online IDE powered by Visual Studio Code ⚡️
https://stackblitz.com
MIT License
10.35k stars 934 forks source link

Is it possible to use fs.readFileSync, when try to read a file im getting an empty file content. #2063

Open ofergoli opened 2 years ago

ofergoli commented 2 years ago

Description of Bug

Cannot read a file locally using fs, expected behavior is to be able to read a file.

Steps to Reproduce

Here is an example of a sandbox that tries to read the local index.html file https://stackblitz.com/edit/js-lcr14j?file=index.js But it's not working.

Expected Behavior

To be able to read a local file.

Screenshots/Screencast

image

Additional Context/Questions I saw when tried to drill down the code and saw some error related to this message: "Flag passed to readFile must allow for reading"

So it possible to have access to read local files?

Thanks!

Jacob-Lockwood commented 2 years ago

It's because you're using the HTML/CSS/JS template, which only supports browser code and packages. If you want to run Node.js you need to use the node template: node.new

ofergoli commented 2 years ago

Oh now i see the compare between EngineBlock and WebContainers, To bad i don't have a full node.js env with EngineBlock. There is a way to setup node.js with html/css/js serving? and see the ui along side the nodejs server?

Jacob-Lockwood commented 2 years ago

You could just use the node template and start a HTTP server. There's also templates for backend libraries like Express, NestJS, Koa, etc. when you click Backend on the Create A Project screen.

ofergoli commented 2 years ago

Actually it’s not good enough for me, i need to show the console but its not optional. Too bad.

Jacob-Lockwood commented 2 years ago

What do you mean you "need to show the console"? to you mean the terminal? With the node template you can see the terminal. Do you mean the browser console? There's a button to open it if you have a page open. Take a look at the Express example: https://stackblitz.com/fork/express-simple

ofergoli commented 2 years ago

Well it's more complex than that, basically i have a website that teach people how to write code. As part of the process people solve simple questions that i made, So i need to enable the users to write down html/css/javascript code, Read their files locally, send them to my server for testing, and show them the result. As part of the studying the need to be able to see a simple output Such as console you have in the 'javascript' template.

So when the user try to console.log something, he can see the output inside the embed browser view. So for now i cant use stackblitz to do so :(