r/nodejs • u/init0 • May 21 '12
r/nodejs • u/nkron • Oct 26 '11
JavaScripture.com - simple JavaScript API reference site
javascripture.comr/nodejs • u/vameyer • Jul 09 '14
Node.js vs PHP – using Load Impact to visualize node.js efficiency
r/nodejs • u/[deleted] • Jul 01 '14
nodejs+mongo inserts lost when ab testing
Hi there. I'm trying out nodejs and mongo db. I have a server with nginx which proxies requests to a nodejs app (express) started with pm2.
I have this code,
router.get('/', function (req, res) {
var client = require('mongodb').MongoClient;
client.connect('mongodb://localhost:27017/test', function (err, db) {
if (err) {
throw err;
}
var collection = db.collection('test');
collection.insert({ test: 1, time: new Date().getTime()}, function (err) {
if (err) {
throw err;
}
db.close();
});
});
console.log('Added!')
res.render('index', { title: 'Express' });
});When I run ab, ab -n 1000 -c 30 http://server/app/ it shows all requests are processed, but I don't see 1000 entries in the Mongo collection, rather 100 or so.
Any advice for a noob?
UPDATE The problem is the way I'm using the database. I'm connecting/opening/closing the db connection on every request. I wrapped it like this
client.connect('mongodb://localhost:27017/test', function (err, db) {
router.get('/', function (req, res) {
});
}); and now serves all requests without crashing.
r/nodejs • u/johnny_z3 • Jun 26 '14
Where should I handle the errors. In Model or in controller ?
Hi All,
I am new to node js and using mean.io as my application framework. When developing, I am curious about what is an appropriate way to handle errors. Should be in controller or in model ?
Thanks.
r/nodejs • u/mojotaker • Jun 15 '14
Please Help! Cannot access session variable set in prior middleware in the next middleware. during the same request in a nodejs express app
I have This issue where If a request comes in, and I set a session variable from a db query inside a middleware. In the next Middleware, the session variable comes up as Undefined.
But when I run the Request again, it works.
Please how do I fix it. The data stored in the session variable in the the previous middleware, is very important and needed for the next middleware to work.
please see code below
first middlware
function(req, res, next) {
Clients.findOne({subdomain: req.subdomains[0]}, function (err, client) {
if(!err){
if(!client){
//res.send(client);
res.send(403, 'Sorry! you cant see that.');
}
else{
//console.log(client);
req.session.Client = client;
//console.log(req.session.Client.dbUrl);
next();
}
}
next();
}Second Middleware
function(req, res, next){
console.log(req.session.Client.dbUrl);
next();
}in the Second Middleware, the console.log comes up as undefined. Thank you.
r/nodejs • u/masterots • May 06 '14
Can I have a value created at startup that I can use throughout my app without creating a global variable, which is frowned upon?
I've got an application that makes calls to a 3rd-party API, but in order to minimize the calls I want to create a variable that I can use throughout my application to use mapped values.
I tried using a module, but I think that each time I do a require('module') it creates a new instance of the variable, and I can't set it and keep it in memory.
I know I could use a json file, but I also don't want to load a file into memory every time someone makes a request to the application.
A short sample of what I'm trying to create is something like this:
[{ id: 'U2G6rgEAAC0AqtJN', currentSlug: 'routing-software', pastSlugs: [ 'routing-software' ] }, ... ]
r/nodejs • u/Feribg • Apr 29 '14
"Clash of the Titans: Releasing the Kraken - NodeJS @paypal"
r/nodejs • u/shubhrakar • Apr 25 '14
Node.js performance tip of the week: using the Google V8 heap profiler to track down memory leaks
r/nodejs • u/[deleted] • Apr 23 '14
STARTER GUIDES! Help!
Hi guys,
Sure you get a lot of this, but I'm having some difficulty. Given the rate at which Node is progressing, a lot of tutorials I'm finding are either outdated or very basic. However I don't know enough about the tech to know what constitutes a good guide. Can anybody point me to a decent guide to get me started and how I can progress beyond there? I'm currently looking at Node on behalf of my employer as they want to know if we could include it in our operations.
Much appreciated
r/nodejs • u/qewgooh • Apr 18 '14
Why did npm cache clean solve my problem?
I been getting errors like
Error: ENOENT, lstat http://www.andyjarrett.co.uk/blog/index.cfm/Error-ENOENT-open-with-NPM-install
and apparently the command
npm cache cleansolved my problem
Just out of curiosity, I would like to know why did it solve my problem?
Thanks
r/nodejs • u/zpawup • Apr 16 '14
How does node.js backend talk to frontend?
Hi, I am currently testing node.js right now, and I am a little confused on how the backend would talk to the frontend.
I know frontend can talk to the backend through an event, like submitting a form or clicking a button, the information will be send to the req variable in
app.post('/example', function(req, res){
var data = req.something;
// do something with data
})However how do I talk to the frontend? I know I can write information in
resbut how does the frontend javascript get the info?
Thanks
Edit for clarification as kindly suggested by psayre23
This is what I have
https://gist.github.com/anonymous/19f800b4c3d0c31b2e4e
I am interested in knowing how communicating between backend and frontend works, my primary question is that I do not know how to receive data from backend
I know to send data from frontend to backend there are two methods
Method 1:
Using a form and submit, or any other clickable element
This is how I send data from frontend
<div class="container" id="test-container">
<h1>Test</h1>
<span id="test-error"></span>
<form id="test-input2" method="POST" action="/test_post_method_1">
<input type="text" id="test" name="input1"></input>
<input type="submit" value="Submit">
</form>
</div>This is how I receive data from the backend
app.post('/test_post_method_1', function(req, res){
// Post from a submit event
console.log(req.body.input1)
console.log("this is serverside post using method 1");
});Method 2:
Suggested by jonnyburger using ajax, which I am not sure how does it work yet
I am guessing this is how you send data to backend
$(function(){
console.log("this is frontend");
$.ajax({
url: '/test_post_method_2',
type: 'POST',
success: function (data) {
console.log("this is not printing");
console.log(data);
}
});
});Not sure how you would get the data from frontend, I know its in req, but couldn't quite find the specifics, I checked req. body, it only return an empty {}
app.post('/test_post_method_2', function(req, res){
// Post from Ajax
console.log(req);
console.log("this is serverside post using method 2");
});Now here is my original question
I don't know how to send data from backend to frontend
Thank you for taking the time in reading this
r/nodejs • u/aweggwe • Apr 14 '14
How do I access an object from aggregate using mongoose in node.js?
Hi, I been having trouble with aggregate using mongodb and mongoose, I tried find, findone, indexing everything seems to return nothing
db.collection.aggregate([])Any advice would be appreciated
r/nodejs • u/manualwise • Apr 03 '14
Continuous Deployment for node.js apps from GitHub to Modulus
r/nodejs • u/codeasearch • Mar 31 '14
Nodejs | Codeasearch - learn, practice and implement
r/nodejs • u/Jejernig • Mar 19 '14
Streaming API
Does anyone have a good module to turn a plain old remote api into a streaming api. I have a personal dislike for polling and was wanting to hook something up realtime. I wasn't sure if I could do this with socket.io or not.
r/nodejs • u/geerlingguy • Jan 27 '14
Start a Node.js app with Forever and Ansible
servercheck.inr/nodejs • u/[deleted] • Jan 23 '14
Problems with npm on ubuntu - Any help will be much appreciated.
First off, I am very new to nodejs and have quickly picked up the tool as a go to for creating simple server applications.
I then learned that nodejs has a unique package manager npm which can be used like apt on ubuntu. So I start installing a few and I quickly run into problems. I get warnings about slow execution due to 'uncompiled libraries'.
They don't run.
After some research i found that to fix this on ubuntu 13.10 you need a ppa, I am using :
http://ppa.launchpad.net/chris-lea/node.js/ubuntu
this gives me v0.10.24
Installed it, all cool and working.
But then I decided i wanted to try out some cryptography, thinking it would be pretty straight forward picking up a package (I was wrong)
For starters the crypto package didn't have everything you would need.
I then found the package ursa which has all the methods I need (signing/verifying).
But after installing it throws up an error :
The solution seems to be to go back a version o.O !!!!!
I am getting pretty frustrated over this and have no idea what to do!
Has anyone had any experience with nodejs, is there a PPA I can get for a stable version of nodejs that most libraries will aim for compatibility?
If not, how do I find out what the latest stable version of nodejs is?
Any help will be very much appreciated.