Skip to content
This repository was archived by the owner on Aug 15, 2024. It is now read-only.

fs undefined #29

Closed
jannavarro opened this issue Jun 30, 2015 · 5 comments
Closed

fs undefined #29

jannavarro opened this issue Jun 30, 2015 · 5 comments

Comments

@jannavarro
Copy link

In my js file I have:

var fs = require('fs');

when I tried fs.readFileSync(..somefile);

Error is: fs.readFileSync is not a function

Is there any setup needed?

@zenflow
Copy link
Contributor

zenflow commented Jun 30, 2015

The readme says under Module exports fs: null // core module without browser replacement

Also, see the relevant source code

So, fs, and a handful of other node core libs that are exported in this library, are not in any way implemented for browser.

What were you expecting this to do browser-side anyways?

@jannavarro
Copy link
Author

@zenflow Thank you. I saw the readme; I just thought that setting it to null means that some of the node-libs-browser code would set it to a default value. I am looking at atom editor's fs-plus code and they are using nodejs fs inside their code which is reading some file configuration on the client-side so I thought I can use fs on client-side. If this is not applicable on the browser-side do you think they did anything special to use it?

@zenflow
Copy link
Contributor

zenflow commented Jun 30, 2015

Yup.. very special. Read a bit about electron.. formerly known as atom-shell.

It's used to make desktop apps. It allows you to use both (a) nodejs API's and (b) browser API's together. There is no browser-side separate from server-side. It's just one side, and it's both brower-side and server-side. Does that make sense?

If you're making a web-app (as opposed to a desktop app), you won't be able to use the 'fs' module in your browser-side code. What filesystem would it access? Besides this filesystem API which is only implemented in Chrome, browsers don't grant any filesystem privileges (read or write) to web-apps.

If you're looking to simulate the usage of 'fs' in your browser-side code, to, for example, include static assets/files in your build, I'm sure this is possible with webpack, but I'm not yet very knowledgeable about it. Also, I'm not sure why someone would want to do that, since webpack's normal way of bundling static assets is so easy.

Anyhow, we should probably close this issue since we've diverged from the topic of issues with this repo.

Gitter is pretty awesome for these types of conversations, and it looks like there is a webpack community there.

Good luck!

@jannavarro
Copy link
Author

@zenflow I appreciate the comprehensive explanation as I am new to web programming and the info you gave me really help.

I will be translating this to a desktop app but I am first building the core structure of my app in pure javascript so that I can use it in different web frameworks such as React and Angular depending on which would fit my goals for the app. I will be using fs the same way as atom does which is to read config files. I first thought that atom did everything mainly in javascript and just used electron to translate it in a desktop app but I now realized that it is tightly coupled with electron and chromium. I will just mock the files now.

Thanks also for introducing me to Gifter.

@zenflow
Copy link
Contributor

zenflow commented Jul 7, 2015

@jannavarro My pleasure :)

Go team open-source!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants