Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
geeves
Sep 16, 2004

Skandranon posted:

I'd break everything down into smaller parts until the 'super controller' had no actual code left in it.

This is really want I want to do. It's just not the easiest to sell in corporate environment because "everything works". My opinion (and agreed upon) is that the current implementation is completely wrong.


Everything they did was in an init or return block that was just a clusterfuck.

Adbot
ADBOT LOVES YOU

Withnail
Feb 11, 2004
I know IŽḿ a javascript idiot but how exactly does

if (myVariable) {

}

evaluate for non-booleans?

for null, empty string, undefined, int = 0, etc

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

Withnail posted:

I know IŽḿ a javascript idiot but how exactly does

if (myVariable) {

}

evaluate for non-booleans?

for null, empty string, undefined, int = 0, etc

Here's a MDN article on falsy values in js: https://developer.mozilla.org/en-US/docs/Glossary/Falsy

It explains it better than I would, so read that.

Withnail
Feb 11, 2004
Perfect thanks

darthbob88
Oct 13, 2011

YOSPOS
Knockout question: How should I display hierarchical data? I'm trying to put up a catalog of my music, sorted by artist/album/file. I can display the artist name just fine, but showing a list of their albums is proving difficult. I suppose I can just do a list of artists that, when clicked, sends an AJAX call for a list of their albums, but I'd rather at least find out what's going wrong here.
HTML:
code:
<ul id="albumListing" data-bind="foreach: artists">
    <li data-bind="text: artist_name">
        <ul data-bind="foreach: artists.album">
            <li data-bind="text: album_title"></li>
        </ul>
    </li>
</ul>
Data:
code:
[{artist_name: "John Jacob Jingleheimer Schmidt", album: [{album_title: "His name" }, {album_title: "Is my name too"  }] }] 
ETA: Actually, I think I found the problem. Knockout is correctly setting the text of the topmost li to artist_name, and completely overwriting the album_title listing below it. The below code is working fine.
code:
<ul id="albumListing" data-bind="foreach: artists">
    <li>
        <span data-bind="text: artist_name"></span>
        <ul data-bind="foreach: album">
            <li>
                <span data-bind="text: album_title"></span>
            </li>
        </ul>
    </li>
</ul>

darthbob88 fucked around with this message at 19:08 on Oct 11, 2015

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
Node development question. In the past on my home (Windows) machine I have utilized XAMPP and just done PHP style websites.

For work now I am writing in Node and I absolutely love it, but I am writing in a very specific parallels enviornment for product deployment on its own linux OS. However I am curious about two things, what would be the best place to go for hosting a website that uses a node backend? And is there anything equivalent to xamp but for node, something easy to setup on my windows machine which would let me start prototyping stuff with ease?

edit: Nevermind, I can see that setting up node is quite easy for windows, but I still am curious about where to go for web server stuff. Also should I stick to v0.12 or should I bite the bullet and go V4.2?

Knifegrab fucked around with this message at 00:52 on Oct 14, 2015

my effigy burns
Aug 23, 2015

IF I'M NOT SHITPOSTING ABOUT HOW I, A JUNIOR DEVELOPER IN JAVASCRIPT KNOW EVERYTHING THERE IS TO KNOW, PLEASE CHECK TO BE SURE MY ACCOUNT WAS NOT COMPROMISED BY A CLIENT-SIDE BOTNET, TIA

Knifegrab posted:

edit: Nevermind, I can see that setting up node is quite easy for windows, but I still am curious about where to go for web server stuff. Also should I stick to v0.12 or should I bite the bullet and go V4.2?

I've never used PHP/XAMPP so I'm not sure exactly what you're looking for. As for Node versions, 90% of the stuff I use doesn't have support for 4.xx yet.

But for the discerning gentleman or lady interested in experiencing all life has to offer might I suggest: https://github.com/OiNutter/nodenv

Spraynard Kruger
May 8, 2007

Knifegrab posted:

edit: Nevermind, I can see that setting up node is quite easy for windows, but I still am curious about where to go for web server stuff. Also should I stick to v0.12 or should I bite the bullet and go V4.2?

I switched from v0.10.x to v4.x the other week and nothing broke, you should be fine.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Knifegrab posted:


edit: Nevermind, I can see that setting up node is quite easy for windows, but I still am curious about where to go for web server stuff. Also should I stick to v0.12 or should I bite the bullet and go V4.2?

Node has an HTTP server built-in. There are libraries built on top of it (such as express) to simply routing and middleware. For production you still want something like nginx or apache as the front-end server that proxies to the node process, but for development it doesn't matter.

Zasze
Apr 29, 2009

three posted:

So wasn't sure whether to put this in this thread or the Web Dev thread (which seems to be mostly JS), but... I've been trying to learn JavaScript, and I have a few thoughts. Was hoping to bounce them off you JS Gurus.

  • Are Frameworks like Angular/React/Ember/Backbone competitors to jQuery?
  • React's style of putting so much code together and using JSX seems really ugly to me. Seems like the lack of separation is bad. Angular seems much more visually appealing, but I've read on the forums some folks aren't a fan of it.
  • Why so much love for MongoDB in the JS community?
  • All the tutorials I've seen for Express involve using it to create an API (which is awesome), but are there any other reasons for it?
  • I've been using Atom and I like it (but I'm ignorant of anything better), but I rarely see it used in videos. Should I be using Sublime or something else?

1. Yes and no they often seek to stream line the development process and get through the hurdles of developing large applications on the client side.
2. I dislike JSX from years and years working with jsp's but some people seem to really like it, the cool thing about react is that it doesnt force either on you and both are equally viable either js or jsx.
3. People love mongo because its a database that uses json so it meshes incredibly well with javascript and i highly recommend it for learning how to make apps. Do not however use it for anything production or if you care about the integrity of the data.
4. Express is a framework for building api's so you will only see tutorials for creating api's. express is a framework for node enhancing node's normal operations to allow for easy creation of api's.
5. Atom was terrible for a long time but it seems more or less pretty ok now, sublime is still the king of the hill for text editing and webstorm if you want a more robust editor.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Zasze posted:

4. Express is a framework for building api's so you will only see tutorials for creating api's.
Completely, totally incorrect. Express.js is a top-to-bottom server-side web framework explicitly designed to parallel Ruby's Sinatra framework. There's an entire section in the documentation on using template engines if you want to do some or all of your rendering on the server.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

necrotic posted:

Node has an HTTP server built-in. There are libraries built on top of it (such as express) to simply routing and middleware. For production you still want something like nginx or apache as the front-end server that proxies to the node process, but for development it doesn't matter.

Ugh I am lost. When I want to run my test server I have to run my expressServer.js file using node. I am using a 1and1 host and its easy enough to upload a php structure and index.html, but I cannot figure out how to implement a node files on my webhost. I feel pretty dumb right now.

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Knifegrab posted:

Ugh I am lost. When I want to run my test server I have to run my expressServer.js file using node. I am using a 1and1 host and its easy enough to upload a php structure and index.html, but I cannot figure out how to implement a node files on my webhost. I feel pretty dumb right now.

It depends which service tier or whatever your 1and1 is on. Node.js also needs to be run as a self-serving long-running application or somehow has to be setup like PHP is with Apache. If you want help you'll have to figure out whether or not 1and1's hosting will allow you to run long-running node processes.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Knifegrab posted:

Ugh I am lost. When I want to run my test server I have to run my expressServer.js file using node. I am using a 1and1 host and its easy enough to upload a php structure and index.html, but I cannot figure out how to implement a node files on my webhost. I feel pretty dumb right now.

Most shared hosts run Apache, not node. You need to use something else.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Knifegrab posted:

Ugh I am lost. When I want to run my test server I have to run my expressServer.js file using node. I am using a 1and1 host and its easy enough to upload a php structure and index.html, but I cannot figure out how to implement a node files on my webhost. I feel pretty dumb right now.

Shared hosting will rarely support Node.js apps. Its possible, but not as simple as "upload this js file and it works!". http://stackoverflow.com/questions/17529613/why-node-js-cant-run-on-shared-hosting

Heroku is relatively simple (for a non-shared platform): deploying is as simple as a git push, but does require some initial setup which the linked doc outlines.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
I made a post in the web hosting thread, hopefully someone there can help me. I am assuming, when you say long-running application you mean the fact that my express server must be running indefinitely?

Is there a better way to run a node server than that? In all my test development when I want to run my server I just do "node expressServer.js" and my express server starts listening on the appropriate port. However if anything goes wrong my expressServer crashes and exits, when I am in development obviously I can just restart the process but how the heck do I handle an exception like that when running production. Obviously proper error handling should prevent such a thing from happening but even best case scenario there is always something that could go wrong!

edit: Thanks Heroku looks really cool, I will take a peak!

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Knifegrab posted:

I made a post in the web hosting thread, hopefully someone there can help me. I am assuming, when you say long-running application you mean the fact that my express server must be running indefinitely?

Is there a better way to run a node server than that? In all my test development when I want to run my server I just do "node expressServer.js" and my express server starts listening on the appropriate port. However if anything goes wrong my expressServer crashes and exits, when I am in development obviously I can just restart the process but how the heck do I handle an exception like that when running production. Obviously proper error handling should prevent such a thing from happening but even best case scenario there is always something that could go wrong!

edit: Thanks Heroku looks really cool, I will take a peak!
App servers almost always include some kind of supervisor that will restart the process automatically if it crashes.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Knifegrab posted:

I made a post in the web hosting thread, hopefully someone there can help me. I am assuming, when you say long-running application you mean the fact that my express server must be running indefinitely?

Is there a better way to run a node server than that? In all my test development when I want to run my server I just do "node expressServer.js" and my express server starts listening on the appropriate port. However if anything goes wrong my expressServer crashes and exits, when I am in development obviously I can just restart the process but how the heck do I handle an exception like that when running production. Obviously proper error handling should prevent such a thing from happening but even best case scenario there is always something that could go wrong!

edit: Thanks Heroku looks really cool, I will take a peak!

Running the process indefinitely is literally the only way to use node for web work. As Vulture Culture said, you want to use a supervisor of some kind (systemd/upstart/sysv if you have access, but you can use a user land supervisor if you must) to auto-restart on crashes. Heroku handles this for you!

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

necrotic posted:

Running the process indefinitely is literally the only way to use node for web work. As Vulture Culture said, you want to use a supervisor of some kind (systemd/upstart/sysv if you have access, but you can use a user land supervisor if you must) to auto-restart on crashes. Heroku handles this for you!

So as a follow up, do you work for Heroku? Just curious because you speak very highly of it, not to say it isn't a good service but I just wanted to check.

Also Heroku seems very cool but I am worried about pricing/performance. I pay very little for my current hosting (less than a hundred a year), my current project gets about 100,000 visits a month and the servers hold up just fine, never have any loss of perforamnce or anything.

However with Heroku it seems like their base minimum plan, which would still cost me well over a hundred a year, isn't that great. Downtime on my Database every month, and what seems like a very limited number of works. And to just get a database that does not have downtime, I would have to pay an extra 50 a month, which is very excessive. Maybe I am misunderstanding but would Heroku's "Hobby" level tier even perform for 100k visits a month?

Huzanko
Aug 4, 2015

by FactsAreUseless
Is MongoDB pretty much a bad choice for ~99% of applications?

I'm trying to decide between MEAN or Rails for tabletop gaming app I'm building. It'll probably be high-write/read, if that makes a difference.

I am leaning towards ActiveRecord (Rails) and PostgreSQL but I am kind of itching to try MEAN out but it's tough to get unbiased, up-to-date information about MongoDB half the time.

I'm not sure if Mongo's schemaless design will benefit something that's basically a DB for D&D-like characters and all the things that entails.

necrotic
Aug 2, 2005
I owe my brother big time for this!

Knifegrab posted:

So as a follow up, do you work for Heroku? Just curious because you speak very highly of it, not to say it isn't a good service but I just wanted to check.

Also Heroku seems very cool but I am worried about pricing/performance. I pay very little for my current hosting (less than a hundred a year), my current project gets about 100,000 visits a month and the servers hold up just fine, never have any loss of perforamnce or anything.

However with Heroku it seems like their base minimum plan, which would still cost me well over a hundred a year, isn't that great. Downtime on my Database every month, and what seems like a very limited number of works. And to just get a database that does not have downtime, I would have to pay an extra 50 a month, which is very excessive. Maybe I am misunderstanding but would Heroku's "Hobby" level tier even perform for 100k visits a month?

I do not. I've used them a bit in the past, and for something like Node or Ruby they are probably the easiest to get up and running with. Their "Hobby" tier may work, but its not intended for that much traffic. Once you get off of shared hosting things start to get a bit pricier unless you manage everything yourself; which simply shifts the cost to time you spend instead of money you spend.

Noam Chomsky posted:

Is MongoDB pretty much a bad choice for ~99% of applications?

I'm trying to decide between MEAN or Rails for tabletop gaming app I'm building. It'll probably be high-write/read, if that makes a difference.

I am leaning towards ActiveRecord (Rails) and PostgreSQL but I am kind of itching to try MEAN out but it's tough to get unbiased, up-to-date information about MongoDB half the time.

I'm not sure if Mongo's schemaless design will benefit something that's basically a DB for D&D-like characters and all the things that entails.

Mongo has a terrible track record. If you want schema-less (which is not as useful as it sounds in most use cases) use Postgres with a JSON column, its highly performant (especially in 9.4+) and you still have all the goodies an RDBMS.

edit: Check out the Jepsen review of Mongo.

necrotic fucked around with this message at 20:05 on Oct 14, 2015

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Noam Chomsky posted:

Is MongoDB pretty much a bad choice for ~99% of applications?

I'm trying to decide between MEAN or Rails for tabletop gaming app I'm building. It'll probably be high-write/read, if that makes a difference.

I am leaning towards ActiveRecord (Rails) and PostgreSQL but I am kind of itching to try MEAN out but it's tough to get unbiased, up-to-date information about MongoDB half the time.

I'm not sure if Mongo's schemaless design will benefit something that's basically a DB for D&D-like characters and all the things that entails.
Some of the historical data integrity problems with MongoDB have been resolved, especially in the 3.0 release. Many of the failure conditions that cause data loss in MongoDB are related to partial network partitions, and are very difficult to trigger unless you have a very high write load to a sharded database at the exact moment a partition occurs. A large number can be worked around by requiring a majority of nodes to acknowledge operations to a database/document collection. In other words: these are real problems, and they certainly affect people in the real world, but they predominantly affect applications working at extreme scale, when you absolutely must scale out and you cannot scale up to improve your performance any further. If you're looking to prototype something quickly so you can ship, you can do a lot worse than Mongo -- namely, by picking anything that causes you not to get software into the hands of users. As others have pointed out, PostgreSQL 9.4 has some really great schemaless features also.

German Joey
Dec 18, 2004

Noam Chomsky posted:

Is MongoDB pretty much a bad choice for ~99% of applications?

yes.

Skandranon
Sep 6, 2008
fucking stupid, dont listen to me

Noam Chomsky posted:

Is MongoDB pretty much a bad choice for ~99% of applications?

If you aren't 100% sure that MongoDB is perfect for your situation, don't use it.

Jabor
Jul 16, 2010

#1 Loser at SpaceChem
If your data is relational, you almost certainly want to use a relational database instead of trying to build one on top of a key-value store.

Your data is probably relational. If it's not relational, you'll probably find a different key-value store fits your specific use case better.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

99% of applications matter so little in terms of data management that ease of developer use trumps everything else. If you're in the other 1% you know it and you're not asking about storage architectures in a JS thread.

Huzanko
Aug 4, 2015

by FactsAreUseless

Subjunctive posted:

99% of applications matter so little in terms of data management that ease of developer use trumps everything else. If you're in the other 1% you know it and you're not asking about storage architectures in a JS thread.

A RDBMS provides a lot of ease of developer use most sometimes...

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Sure does, if your data's tabular and your queries relational. If you have data of other shapes, like graphs, then sometimes less so. RDBMS are fine to use, I'm not arguing against them, or for any specific storage tech. I just think that if people feel like a tech is going to be comfortable for them, then ":ohdear: what about ill-times network partition" pearl-clutching isn't helpful. More likely to lose because nobody's testing the backup tools than because you lost consistency between shards.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
I am looking to get acquainted with supervisor stuff for javascript files that need to keep running even if they crash, was wondering if anyone had any tips for that since googling javascript supervisor is giving me mixed results. I found a package called forever but it appears to only be as far as 0.15 so I'm not sure if its a good bet anymore.

Knifegrab fucked around with this message at 09:47 on Oct 15, 2015

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Why not use something a bit more mature if you want a userspace process manager, like supervisord (http://supervisord.org)

There's absolutely no reason you need to use JavaScript written programs to manage node processes.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.
PM2 is a really robust Node process manager with Keymetrics integration. We use it all over the place.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

Vulture Culture posted:

PM2 is a really robust Node process manager with Keymetrics integration. We use it all over the place.

THis seems really cool but testing it, it only seems to restart my script after it crashes four times then it never restarts again...

no_funeral
Jul 4, 2004

why
What would the 'smart' way to handle determining whether or not a 'touchmove' event originated within a specific div be? i tried a recursive 'isDescendent' type function but it didn't seem good.


nevermind i just used target.parents(*parent*).length

no_funeral fucked around with this message at 21:41 on Oct 15, 2015

my effigy burns
Aug 23, 2015

IF I'M NOT SHITPOSTING ABOUT HOW I, A JUNIOR DEVELOPER IN JAVASCRIPT KNOW EVERYTHING THERE IS TO KNOW, PLEASE CHECK TO BE SURE MY ACCOUNT WAS NOT COMPROMISED BY A CLIENT-SIDE BOTNET, TIA

Noam Chomsky posted:

Is MongoDB pretty much a bad choice for ~99% of applications?

I'm trying to decide between MEAN or Rails for tabletop gaming app I'm building. It'll probably be high-write/read, if that makes a difference.

I'm going to be doing a project with node and mySQL soon, so it's not like it's MEAN or nothing if you want to use the crunchy goodness of npm and server side javascript. But yeah, if you already know both I would guess you can get up and running sooner with Rails.

Huzanko
Aug 4, 2015

by FactsAreUseless

my effigy burns posted:

I'm going to be doing a project with node and mySQL soon, so it's not like it's MEAN or nothing if you want to use the crunchy goodness of npm and server side javascript. But yeah, if you already know both I would guess you can get up and running sooner with Rails.

Yeah, I know Rails fairly well and Ruby fairly well and I'm currently learning more about the intricacies of Ruby as a language, outside the context of Rails. I also know some SQL.

The language I know best if JavaScript, though, and I know AngularJS very well, and I'm fairly familiar with Node and Express. So, deciding on which stack to use is fairly tough, since I know two of trendy stacks well enough to create some apps.

I really enjoy Rails and as well as I know and as much as I enjoy JavaScript, it does make me want to shoot myself at times. So, I'm probably looking at a Rails JSON API and an AngularJS front-end.

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.
I have a script I need to essentially run forever (its not an express server its a web api scraper) but it just seems to stop randomly all the time and I cannot pinpoint why that is. At the end of my promise loop (which was a pain to write) it has a then, fail, and finally, however it never outputs any of the logs in those parts of the code so it would seem it never actually "ends" but it would also seem it never explicitly fails or crashes anywhere, it just sort of ... hangs!

qntm
Jun 17, 2009

Knifegrab posted:

I have a script I need to essentially run forever (its not an express server its a web api scraper) but it just seems to stop randomly all the time and I cannot pinpoint why that is. At the end of my promise loop (which was a pain to write) it has a then, fail, and finally, however it never outputs any of the logs in those parts of the code so it would seem it never actually "ends" but it would also seem it never explicitly fails or crashes anywhere, it just sort of ... hangs!

Sounds like you forgot to call a callback somewhere prior to that final section you mentioned. Can we see the code?

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

qntm posted:

Sounds like you forgot to call a callback somewhere prior to that final section you mentioned. Can we see the code?

Unfortunately its not something I can paste here, I have verified that all of the end points do continue with the process, I added a ton of logging tools so hopefully I can narrow down where the hang occurs.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Could be a GC pause. Try running it in verbose mode and looking for 'mark-sweep' in the logs to see if the timing coincides.

Adbot
ADBOT LOVES YOU

Knifegrab
Jul 30, 2014

Gadzooks! I'm terrified of this little child who is going to stab me with a knife. I must wrest the knife away from his control and therefore gain the upperhand.

Munkeymon posted:

Could be a GC pause. Try running it in verbose mode and looking for 'mark-sweep' in the logs to see if the timing coincides.

Would such a pause be indefinite though? The script doesn't just hiccup, it straight up fails to continue.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply