Thursday, January 31, 2013

Using Nodejs as a fileserver


Creating a Simple Fileserver.
Tip #2
I wanted a simple fileserver, I tried looking for a variety of search terms, but finally came upon simple file server. I came across the post linked by Tip #2 above, but it wasn't exactly clear what it was doing exactly.

The documentation isn't 100% clear so I played with it a little, (and added some comments to one of the posters).

I used connect.

Install it with npm connect.

Next use the following code:

var connect = require('connect'),
    http = require('http');
connect()
    .use(connect.static('pathyouwishtoserve'))
    .use(connect.directory('pathyouwishtoserve'))
    .listen(8080);
.use(connect.static('pathyouwishtoserve')) tells the server where to look for files.
.use(connect.directory('pathyouwishtoserve')) tells the server to return the following directories contents.

If you now navigate to http://your-ip-address:3000 you'll get a list of the directory contents,
if you add a /filename to that path you'll get the file.


I'll be posting tips as I come across them of using NodeJS as an intranet fileserver.
Long story short, I want to build a Roku app that will refer to the NodeJS server for where to find the files. I figure it'll be simpler than PLEX, and also faster (I'm hoping). Once I get the stuff running I'll plan on running it on my Pogo Plug as a media server for my Roku, totally awesome!

Tuesday, January 29, 2013

Creating a Kindle EBook Part 1


I was looking up how to create an ebook, now according to this website: How to Format Childrens Ebook it's a matter of creating a html file and including some image files, then zipping them all up and sending them to your kindle.

It's not quite that simple these days. When you send that zipped file out to your kindle, amazon splits it up and you get each item pushed to your device, so if you have 3 pictures, you have 3 pictures plus your html ebook.

The fix for that is to create a .mobi file, now there are some sites that do that, also the program Calibre works, but for now I decided to try using Amazon's solution. Kindlegen

I use ubuntu so I'll be giving the ubuntu version, if you want an example in the Windows version, then let me know, and I'll try to update for that!

Here goes.

I found this little trick out, create a file called kindlegen located at /usr/local/bin
enter in the following (I had to use sudo):

#!/bin/bash
exec /kindlegen "$@"
afterwords use the following command
:/>sudo chmod -x /usr/local/bin/kindlegen

Now whenever you want to convert an html file, simply call kindlegen . Ok we're done with that part.


Lets make a book.

First lets try the following

Based on the website I mentioned at the top they suggest naming things page_nn.jpg, etc, however as long as you keep track, it doesn't really matter the naming (it's for simplicities sake).

This particular book has 3 pages. Duplicate the following lines for each page, and you're set.

Save your file as test.html (or whatever you want, just substitute your filename below)

Next we'll actually create our Mobi File.

Navigate to the folder via commandline:
:/>kindlegen test.html

The resulting file will be called test.mobi

Next login to your amazon account check your account settings and scroll down to manage your kindle.

Click Manage Devices

Here you can find your email address to send your mobi file.

Next email your .mobi file to that email address.

When you see the file visible on the Personal Documents Section. Check your kindle and see if the file has arrived. If not, you can "resend" it using the Personal Documents Section.

Good luck!

Sunday, January 27, 2013

Using NodeJS as an Intranet Webserver

I'll be posting tips as I come across them of using NodeJS as an intranet webserver.

Long story short, I want to build a Roku app that will refer to the NodeJS server for where to find the files. I figure it'll be simpler than PLEX, and also faster (I'm hoping). Once I get the stuff running I'll plan on running it on my Pogo Plug as a media server for my Roku, totally awesome!

Tip #1
When running a http://nodejs.org/ port, the IP address should be of the machine you are currently on. I chose the port 8080 as it's the standard http port.

From linux you can find this by doing a simple ifconfig command on the command line. From windows ipconfig should do it.

Then using the example below: (from the NodeJS website)

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(8080, '100.11.1.6');
console.log('Server running at http://100.11.1.6:8080/');

So when you go to another machine such as your phone and access the page 100.11.1.6 you should get "Hello World". When you're able to do this, your Roku can now see the server (when you have the app setup).

The above tip was discovered after a google search to figure out an error. The link is from stackoverflow, and can be clicked above on the Tip #1 link.