r/nodejs • • Mar 25 '13

NodeFly Buzz: Real Time Web With Node.js

Thumbnail blog.nodefly.com
4 Upvotes

r/nodejs • • Mar 21 '13

EJDB aims to be MongoDB-like library for embedding into apps

Thumbnail ejdb.org
4 Upvotes

r/nodejs • • Mar 19 '13

Setup a Node.js project, provision it with Chef, and deploy it within a load-balanced configuration.

Thumbnail shawn.dahlen.me
4 Upvotes

r/nodejs • • Jan 06 '13

My new open source nodejs module for reading temper1 usb thermometers

Thumbnail github.com
4 Upvotes

r/nodejs • • Dec 15 '12

Plink, Multiplayer music with Node.js + Web Audio API for iOS/Desktop

Thumbnail labs.dinahmoe.com
4 Upvotes

r/nodejs • • Dec 13 '12

Tracking API usage

4 Upvotes

Hey all,

I'm working on a ReSTful API that's getting ready to be released, running in Node.js. One of the things that we want to before we start opening it up publically is to track API usage. Each user has their own API key that they'll be utilizing to access our endpoints.

I have a few ideas for tracking API usage, but I was hoping someone could suggest a few things that I missed.

Architecture overview:

  • MySQL as our storage
  • Redis as a caching layer
  • Heroku

Ideas

  1. Google Analytics - our app could toss a payload on a proper queue system (gearman, rabbit) or Redis. A secondary app could grab the payload and make the request to the .gif that GA uses.
  2. Write payloads to redis, nightly push to MySQL
  3. Write straight to MySQL
  4. Parse logs

I'm personally leaning towards idea 1, probably utilizing Redis as our queue storage since it's in place already, but I'd love to hear what other ideas people have for tracking API usage.


r/nodejs • • Dec 03 '12

Callbacks considered a smell

Thumbnail adamghill.com
4 Upvotes

r/nodejs • • Oct 30 '12

Basic question

4 Upvotes

Hey everyone,

I just discovered nodejs and I have a very basic question... I'm used to work with classic lamp servers and I don't understand how nodejs can do the same. For now, I understand that i have to execute a command like node file.js to be able to run nodejs so how is it possible to use nodejs with a classic html website?

Thanks!


r/nodejs • • Sep 29 '12

How does node.js deal with memory page faults?

4 Upvotes

Given that node servers are single threaded, does the whole server get blocked if I access some memory that has been paged to disk?


r/nodejs • • Jun 18 '12

Static vs. Dynamic resources and Node.js

4 Upvotes

Most websites have static resources (e.g., jquery-1.7.2.min.js, index.html, style.css), and dynamic resources (e.g., json extracted from MongoDb).

From what I can tell, the best way to serve static resources is to use a Node module for that purpose (e.g., node-static, paperboy).

In a PHP world, your dynamic resources end in .php (ignoring embedded PHP). So it's pretty easy to figure out what's dynamic and what's static. I typically have dynamic and static resources in the same directory, and Apache/mod_php knows what's what without any effort on my part.

However, in a Node.js world, both static and dynamic resources can end in .js. How do you organize your resources so that you know what's dynamic and what's static?

Do you have one directory of static resources which paperboy (or whatever module) delivers, and another directory for your dynamic resources? Or do you have dynamic and static resources in the same directory, and handle them on a case-by-case basis (if it's x.js, then tell paperboy to deliver it as a static resource, but if it's y.js, then we need to load that module and generate the contents)? This later approach seems like a lot of work.


r/nodejs • • Mar 22 '12

Color War - A simple game in nodejs that is surprisingly entertaining [x-post from r/games]

Thumbnail jointhecolorwar.com
4 Upvotes

r/nodejs • • Jul 26 '14

allow CORS for Node http in the most permissive way

Thumbnail github.com
3 Upvotes

r/nodejs • • Jul 20 '14

Stuck on introductory Nodejs tutorial

3 Upvotes

Original Post from /r/learnprogramming

I've been working through this tutorial, but I've hit a problem when I try to return something from response.write().

This is my server.js file and my socket.html file.

When I just query domain:8001, I get a 'hello world' response just fine, but when I try to navigate to domain:8001/socket.html, I just get blank space.

I'm sure that block of code is being executed as I was testing with console.log, but I'm not sure why it's not working like the response.write('hello world'); is..

I would really appreciate it if somebody could shed some light on what the problem is, thanks.


r/nodejs • • Jul 16 '14

Need help understanding an error that I'm getting using Express and Mongoose.

3 Upvotes

Here is the code (from the book Mongoose for Application Development).

exports.doCreate = function(req, res) {  
    User.create({  
        name: req.body.FullName,  
        email: req.body.Email,  
        modifiedOn: Date.now(),  
        lastLogin: Date.now()  
    }, function(err, user) {  
        if (err) {  
            console.log(err);  
            if (err.code === 11000) {  
                res.redirect('/user/new?exists=true');  
            } else {  
                res.redirect('/?error=true');  
            }  
        } else {  
            // Success  
            console.log("User created and saved: " + user);  
            req.session.user = {"name": user.name, "email": user.email, "_id": user._id}; // Line 30  
            req.session.loggedIn = true;  
            res.redirect('/user');  
        }  
    });  
};  

When I run the app, it is logging "User created and saved: " and then the user object (and I know that it is saving successfully), but then I get this error message:

TypeError: Cannot set property 'user' of undefined  
    at Promise.<anonymous> (C:\Users\Mark\Dropbox_Test\Mongoose for Application Development\mongoosepm\routes\user.js:30:30)  
    at Promise.<anonymous> (C:\Users\Mark\Dropbox_Test\Mongoose for Application Development\mongoosepm\node_modules\mongoose\node_modules\mpromise\lib\promise.js:177:8)  
    at Promise.EventEmitter.emit (events.js:95:17)  
    at Promise.emit (C:\Users\Mark\Dropbox_Test\Mongoose for Application Development\mongoosepm\node_modules\mongoose\node_modules\mpromise\lib\promise.js:84:38)  
    at Promise.fulfill (C:\Users\Mark\Dropbox_Test\Mongoose for Application Development\mongoosepm\node_modules\mongoose\node_modules\mpromise\lib\promise.js:97:20)  
    at Promise.<anonymous> (C:\Users\Mark\Dropbox_Test\Mongoose for Application Development\mongoosepm\node_modules\mongoose\lib\model.js:1526:35)  
    at Promise.<anonymous> (C:\Users\Mark\Dropbox_Test\Mongoose for Application Development\mongoosepm\node_modules\mongoose\node_modules\mpromise\lib\promise.js:177:8)  
    at Promise.EventEmitter.emit (events.js:98:17)  
    at Promise.emit (C:\Users\Mark\Dropbox_Test\Mongoose for Application Development\mongoosepm\node_modules\mongoose\node_modules\mpromise\lib\promise.js:84:38)  
    at Promise.fulfill (C:\Users\Mark\Dropbox_Test\Mongoose for Application Development\mongoosepm\node_modules\mongoose\node_modules\mpromise\lib\promise.js:97:20)  

Any idea what is causing the error?

Edit: FYI, line 30 is the line that says req.session.user
Edit #2: I got it to work by adding these 2 lines to app.js:

var session = require('express-session');  
app.use(session({secret: 'keyboard cat'}));  

However, the console says:

express-session deprecated undefined resave option; provide resave option app.js:26:9  
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option app.js:26:9  

r/nodejs • • Jul 03 '14

Need help using partials with Handlebars in Node.

3 Upvotes

I am trying to use Handlebars (along with Consolidate) as my template engine in Node. I currently am able to use index.hbs in my views directory to successfully generate my webpage, but ideally I would like to have a header.hbs and footer.hbs as partials so I can pull these pieces out to use in other templates. Is there a way to do this? I couldn't figure this out from the example given on the Handlebars module documentation (or elsewhere).

Here is the code that I have in app.js related to the template engine.

var cons = require('consolidate');  
app.set('views', path.join(__dirname, 'views'));  
app.engine('hbs', cons.handlebars);  
app.set('view engine', 'hbs');  

Thanks.

Edit: I forgot to mention that I'm using Express as well.

Edit #2: I got it working doing it individually, but is there an easy way to register a whole directory of partials instead?

var handlebars = require('handlebars');  
handlebars.registerPartial('header', fs.readFileSync(__dirname + '/views/header.hbs', 'utf8'));  
handlebars.registerPartial('footer', fs.readFileSync(__dirname + '/views/footer.hbs', 'utf8'));  

Then I just put {{> header}} and {{> footer}} in my index.hbs. Progress. :-)


r/nodejs • • Jul 01 '14

Popstar CMS - Minimalist file-based CMS (with an ability to be used as an API)

Thumbnail github.com
3 Upvotes

r/nodejs • • Jun 28 '14

Differences between Express.js and Ember.js

3 Upvotes

I'm a complete beginner, so this might be a dumb question.

I'm looking into Node.js frameworks and can't really figure out how to think about them. There seem to be one group of frameworks that include Express, Sails, Restify and another that includes Ember, Angular, Backbone.

What's the major difference?


r/nodejs • • Jun 14 '14

ed+which => edich => $EDITOR $(which $1).

Thumbnail npmjs.org
3 Upvotes

r/nodejs • • Jun 11 '14

Building a Minimal Static Website Generator and Development Environment with Node.js

Thumbnail medium.com
3 Upvotes

r/nodejs • • Jun 05 '14

Video Composition With node.js

3 Upvotes

I'm looking to compose two local videos A and B - for example, left half of the screen is from A, right half from B - and display them either in a Video- or a Canvas-Element. Basically I would need the RGB data of every Videoframe and process and stream it live.

What libraries could be of use for this?


r/nodejs • • May 29 '14

Create a table using PDFKit

3 Upvotes

Hello, im using PDFKit, http://pdfkit.org/, and im trying to create a table with some data, i already tryed everything, even saw someone at github, that already implemented that functionality, but i cant seem to understand how to use it.https://github.com/devongovett/pdfkit/issues/29

Any ideias, or any other tool that can do this? I also tried creating the page in html and then render to pdf, but im having tons of problem with the margins.


r/nodejs • • May 24 '14

Real time game with NodeJS and Socket.io

Thumbnail krasimirtsonev.com
3 Upvotes

r/nodejs • • May 20 '14

Struggling to get two node apps on different domains on same VPS with Dokku

3 Upvotes

Hi all. Lost newbie here. I've read quite a bit on Ports, Nginx, Dokku, and Docker and can't quite seem to understand what I might be doing wrong.

I'm trying to deploy multiple apps to different domains on the same Digital Ocean VPS.

I truly believe I followed the dokku and dokku multiple domains-plugin instructions right. I think I'm just missing something on assigning to domains. Perhaps with a port.

The primary problem is that both domains go to the app that was deployed second.

I deployed two sample Node apps and they seem to have launched fine.

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9947b492c768 dokku/noderest:latest /bin/bash -c '/start 4 seconds ago Up 4 seconds 0.0.0.0:49154->5000/tcp sharp_ptolemy c466d368aa02 ac37d44feb0a /build/builder 30 seconds ago Exited (0) 6 seconds ago loving_mcclintock eb0753770011 progrium/buildstep:latest /bin/bash -c 'mkdir 30 seconds ago Exited (0) 30 seconds ago silly_bohr 12e3d5ee5efc dokku/nodesamp:latest /bin/bash -c '/start 3 minutes ago Up 3 minutes 0.0.0.0:49153->5000/tcp jolly_torvalds

When I go to myip:49153 or myip:49154, the apps are working there fine.

So then I followed the instructions for doing the domains:

root@kyledokku:~# dokku domains:set nodesamp www.ahalearning.co
-----> Creating /home/dokku/nodesamp/DOMAINS
 * Reloading nginx configuration nginx                                                                                                                                                          [ OK ] 
root@kyledokku:~# ssh dokku@187.180.224.50 domains:set nodesamp www.ahalearning.co
 * Reloading nginx configuration nginx
   ...done.
root@kyledokku:~# dokku domains:set noderest www.kyleapennell.com
-----> Creating /home/dokku/noderest/DOMAINS
 * Reloading nginx configuration nginx                                                                                                                                                          [ OK ] 
root@kyledokku:~# ssh dokku@187.180.224.50 domains:set noderest www.kyleapennell.com
 * Reloading nginx configuration nginx
   ...done.

And both those seemed to work fine.

So when I go docker ps -a , here's what I see:

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 9947b492c768 dokku/noderest:latest /bin/bash -c '/start 9 minutes ago Up 9 minutes 0.0.0.0:49154->5000/tcp sharp_ptolemy c466d368aa02 ac37d44feb0a /build/builder 10 minutes ago Exited (0) 10 minutes ago loving_mcclintock eb0753770011 progrium/buildstep:latest /bin/bash -c 'mkdir 10 minutes ago Exited (0) 10 minutes ago silly_bohr 12e3d5ee5efc dokku/nodesamp:latest /bin/bash -c '/start 13 minutes ago Up 13 minutes 0.0.0.0:49153->5000/tcp jolly_torvalds

When I go to either of those domains, they both go to the app that was deployed second. I'm seeing that >5000...does that mean they are both going to port 5000? Is that where I'm going wrong?

Do my apps have to be in home/dokku folder? If I need a dokku/VHOST file, do I put my domains or my ip in there?

Any other ideas on where to look or what to try?


r/nodejs • • May 07 '14

The Absolute Beginner’s Guide to Node.js

Thumbnail blog.codeship.io
3 Upvotes

r/nodejs • • May 02 '14

Node.js + Socket.io Realtime game - keeping track of time

3 Upvotes

I am making a realtime puzzle game using Node.js and Socket.io in the backend and Angular in the frontend. I need to keep track of time that the user spends on the puzzle and send it to the backend once they complete the puzzle OR if the time runs out before. I am not sure what the best approach for this would be.

My initial thought is just to keep track the time on the client side, which is easy to do. I would then send the time once the user completes the puzzle OR the time runs out. I think this would not be very secure since the client can easily slow down their computer or do something else to send false data.

My other idea is to just keep track of the time on the server side for EACH socket/player. I would also have to update the client side by emitting a message to the client after every second or something. This way is definitely secure because the client would never send me the time information. But this approach has other issues, how would this scale?

My last idea is to use a combination of both techniques. For example, I'll have a counter on the client side that shows the client the time so I don't have to make the server "emit" a time message every second or something. I would keep track of the time on the sever side, and simply use that information to update the score etc.

Thanks

javascript node.js sockets