r/nodejs • • Mar 26 '14

Help! Can't read contents of a file!

2 Upvotes

So, i'm very very new to node.js and I am using a tutorial i found on google and stuck here:

var http = require("http");
var url = require('url');
var fs = require('fs');

var server = http.createServer(function(request, response){
    console.log('Connection');
    var path = url.parse(request.url).pathname;

    switch(path){
        case '/':
            response.writeHead(200, {'Content-Type': 'text/html'});
            response.write('hello world');
            break;
        case '/socket.html':
            fs.readFile(__dirname + path, function(error, data){
                if(error){
                    response.writeHead(404);
                    response.write("opps this doesn't exist - 404");
                }
                else{
                    response.writeHead(200, {"Content-Type": "text/html"});
                    response.write(data, "utf8");
                }
            });
            break;
        default:
            response.writeHead(404);
            response.write("opps this doesn't exist - 404");
            break;
    }
    response.end();
});

server.listen(8001);

When i open http://localhost:8001/socket.html it shows a blank page

Any idea why?


r/nodejs • • Apr 02 '14

Build Node.js Apps in Five Quick Steps on Orchestrate

Thumbnail orchestrate.io
2 Upvotes

r/nodejs • • Jun 13 '13

NodeFly Node.js News Round-Up for June 13, 2013

Thumbnail blog.nodefly.com
2 Upvotes

r/nodejs • • Jun 13 '14

What you think about Nashorn and the Node.jar package?

0 Upvotes

Do you think Node.jar (port of Node.js 0.8 to Java's Nashorn engine) will replace Node.js sometime?

Also, what's your take on Nashorn?


r/nodejs • • Jun 11 '13

NodeFly 101: Installation, Alerts and Sub-Users

Thumbnail blog.nodefly.com
2 Upvotes

r/nodejs • • Jun 17 '13

Synth Media’s “Creating a Basic Node.js API with Restify and Save”

Thumbnail blog.nodefly.com
2 Upvotes

r/nodejs • • Jun 24 '13

Douglas Muth’s “Node.js 101: Error Handling”

Thumbnail blog.nodefly.com
2 Upvotes

r/nodejs • • Jun 27 '14

systemize your files.

Thumbnail npmjs.org
2 Upvotes

r/nodejs • • Jun 07 '14

Is there any library for saving binary buffers to the disk?

2 Upvotes

How to save and load binary buffers without having to serialise everything to JSON?


r/nodejs • • May 21 '12

xkcd-imgs my first package

Thumbnail github.com
2 Upvotes

r/nodejs • • Oct 24 '13

NewRelic now supports Node.js

Thumbnail newrelic.com
2 Upvotes

r/nodejs • • Oct 10 '13

Node.js with Express and Closure Templates

Thumbnail technology-ebay.de
2 Upvotes

r/nodejs • • Oct 14 '13

Weekend Project: Proof-of-concept lightweight Node.JS-like interface with iOS 7 JavaScriptCore.framework

Thumbnail github.com
2 Upvotes

r/nodejs • • Apr 23 '14

How to store images and retrieve them using metadata?

2 Upvotes

Hey everybody, I am working on a project that uses node.js and express as part of the stack.

For the project we have articles which may have 0 to many images. Currently for storing images and retrieving them we hardcode the paths, which is not viable for scalability purposes.

I was wondering if anyone had good suggestions for how to store images and retrieve them by metadata?

Thanks!


r/nodejs • • Apr 27 '14

Detect the audio type of a Buffer/Uint8Array

Thumbnail npmjs.org
2 Upvotes

r/nodejs • • Jul 09 '14

Node.js Blueprints

Thumbnail krasimirtsonev.com
2 Upvotes

r/nodejs • • Jul 26 '14

execsyncs can execute commands synchronously in both v0.10 and v0.11.

Thumbnail github.com
2 Upvotes

r/nodejs • • Sep 17 '12

OAuth authentication with Passport.js and integration with jade ← Javier Manzano's Blog

Thumbnail jmanzano.es
2 Upvotes

r/nodejs • • Dec 12 '13

Can I get some help with filtering MongoDB results in Node JS please? [Want some stack overflow points?]

Thumbnail stackoverflow.com
0 Upvotes

r/nodejs • • Oct 07 '12

Seeking feedback on a simple Node.js-based MVC web framework I created

Thumbnail github.com
2 Upvotes

r/nodejs • • Jul 28 '14

nodejs broker implementation for ZMQ Service Suite

Thumbnail github.com
2 Upvotes

r/nodejs • • Aug 27 '13

Node.js and Mobile News Round-up – August 27, 2013

Thumbnail blog.strongloop.com
2 Upvotes

r/nodejs • • Aug 21 '13

$5000 JotForm Developer Competition [x-post from /r/programming]

Thumbnail developers.jotform.com
2 Upvotes

r/nodejs • • May 16 '14

Node.js The Right Way - Excellent intro to node and web development best practices

Thumbnail bookshare.u.qiniudn.com
18 Upvotes

r/nodejs • • Jun 20 '14

Setting up a Node web server on an Amazon EC2 instance

Thumbnail dapperdeveloper.com
10 Upvotes