Jsc: can't find http
Now I'm learning node.js to understand jsc better. I'm using the following code:
const module=require("http");
module.createServer(function(request, response){
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello, world!');
}).listen(8888);
console.log('Server running at http://127.0.0.1:8888/')
But it can't run:
jsc: Error in file require.js at line 209, column 52: Error: Could not find module http
I wonder how to install modules now.
These are two questions.
One is how to install modules. require() is implemented here: https://github.com/holzschu/a-shell/blob/master/require.js, I'm not sure on how to modify it to allow looking at several directories. I think that's here: https://github.com/holzschu/a-shell/blob/f11fdf5f6e6256fcf6a33d075e333d7395458885/require.js#L228 but I'm not sure. Especially since I need to make it dependent on the home directory, which changes at each install.
The other is how to create a server. I'm almost sure that the flavor of JS we have in iOS will not be able to run a server on its own (but I could be wrong).
The other is how to create a server. I'm almost sure that the flavor of JS we have in iOS will not be able to run a server on its own (but I could be wrong).
If a server can't be set, how Jupyter works then? How you made it to work?
./node_modules? Maybe you have to see what they exactly are at that folder.
I'm trying to edit config.paths now, but what is the separator? |, ;, : or space?
I'm trying to edit
config.pathsnow, but what is the separator?|,;,:or space?
Emm it's a list 😂
I'm back on this issue (because of markdown-it.js, see #665). I might make it work this time.
If it works, there will be two place for modules: $APPDIR/node_modules and ~/Library/node_modules. I don't think there will be something like npm in the first run, but pkg install <packageName>. And adventurous users can place what they want in ~/Library/node_modules, with no guarantees that it'll work.
I'm looking for install.sh of npm. It works with dash. We have jsc, tar and curl.
the key part of install.sh:
echo "fetching: $url" >&2
cd "$TMP" \
&& curl -SsL -o npm.tgz "$url" \
&& $tar -xzf npm.tgz \
&& cd "$TMP"/package \
&& echo "removing existing npm" \
&& "$node" bin/npm-cli.js rm npm -gf --loglevel=silent \
&& echo "installing npm@$t" \
&& "$node" bin/npm-cli.js install -gf ../npm.tgz \
&& cd "$BACK" \
&& rm -rf "$TMP" \
&& echo "successfully installed npm@$t"
Thanks a lot for that. My plan is to experiment with more JS packages first, see what works and what doesn't, then see if I can make an automatic install process.
Thanks a lot for that.
My plan is to experiment with more JS packages first, see what works and what doesn't, then see if I can make an automatic install process.
When I have time I'll see if npm works. I really hope so.
After a quick experiment with http-server and others, I can report: a lot of npm packages rely on "os", "fs" and "process". These can be replaced, partially, with jsc, but that means that the code needs to be edited to work. Also "portfinder" does not work with the "require.js" that I have (only one export is active).
At least we should reproduce the built-in modules, such as os, fs, http, https, path, events. Then the remained would work.