Reputation: 2003
I am constructing a node.js application (node.js for the server side and html/javascript/css for the client side). Here is my server.js
file:
var app = require('http').createServer(handler),
fs = require('fs'),
static = require('node-static');
// handle web server
function handler (req, res) {
fs.readFile(__dirname + '/client/client.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading client.html');
}
res.writeHead(200);
res.end(data);
});
}
// creating the server ( localhost:8000 )
app.listen(8000);
// Create a node-static server instance to serve the './static' folder
var staticFiles = new static.Server('./static');
require('http').createServer(function (request, response) {
request.addListener('end', function () {
//
// Serve files!
//
staticFiles.serve(request, response);
}).resume();
}).listen(8080);
I use this as a local server to build my app. On my computer I use the command node server.js
in Terminal to run the server and serve my html and javascript files at this address: http://localhost:8000/
.
I would like to do the exact same thing on a tablet with android. Is this possible and how to do it?
EDIT: I have seen that maybe this is possible here but I'm not sure that the problem is the same.
Upvotes: 1
Views: 2333
Reputation: 4877
I run Node.js on Linux on Android devices. I did it like this:
Steps 9 - 12 were necessary because sudo node --version
would always return the dnf installed version, rather than the n installed version.
Upvotes: 2