Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
[QUOTE=Banana Lord.;45358754]I don't know how node works but it sounds like it doesn't do it how "PHP does it" (which is [i]any[/i] way, really, you're just accustomed to a certain way which doesn't sound like MVC). Instead of making node work like PHP you should be learning how the node workflow...works.[/QUOTE]
But the problem is that I can not find any good way to teach me the correct way to write a dynamic web application in NodeJS. I know that I should not try to mimic the PHP methods in NodeJS and learn the NodeJS workflow, but I doubt it is logical to make every page output the same content by literally writing it out in every file.
The problem is that I'm everything but educated when it comes to NodeJS. I understand the app.get, post and use, but I'm not sure how I would continue from there.
I had the idea of creating several files, i.e. called "/page_elements/header.js", containing a function called render(). then I'd use
var header = require("./page_elements/header.js") and run header.render("home") which would generate the output for the page header, making the "home" button in the navbar highlighted. But again, I doubt this is the correct way, but I really don't know what my options are and I have a hard time finding the different or right options.
That's why I'm asking for someone who's willing to teach me the correct workflow as I the dynamic webserver I want is not really documented anywhere I've looked so far, as opposed to the static fileservers which has 100 different methods and documentations.
[QUOTE=Cyberuben;45358802]But the problem is that I can not find any good way to teach me the correct way to write a dynamic web application in NodeJS. I know that I should not try to mimic the PHP methods in NodeJS and learn the NodeJS workflow, but I doubt it is logical to make every page output the same content by literally writing it out in every file.
The problem is that I'm everything but educated when it comes to NodeJS. I understand the app.get, post and use, but I'm not sure how I would continue from there.
I had the idea of creating several files, i.e. called "/page_elements/header.js", containing a function called render(). then I'd use
var header = require("./page_elements/header.js") and run header.render("home") which would generate the output for the page header, making the "home" button in the navbar highlighted. But again, I doubt this is the correct way, but I really don't know what my options are and I have a hard time finding the different or right options.
That's why I'm asking for someone who's willing to teach me the correct workflow as I the dynamic webserver I want is not really documented anywhere I've looked so far, as opposed to the static fileservers which has 100 different methods and documentations.[/QUOTE]
You basically explained it yourself in your post. Use routes instead of a 'p' variable for a page. If you really need to do something like that (if your pages are dynamic), you can use a get variable or a url parameter. I don't understand what your problem is here.
Nevermind.
[QUOTE=supersnail11;45360829]You basically explained it yourself in your post. Use routes instead of a 'p' variable for a page. If you really need to do something like that (if your pages are dynamic), you can use a get variable or a url parameter. I don't understand what your problem is here.[/QUOTE]
The problem being that the step from PHP -> NodeJS is really difficult. I went over to the ExpressJS IRC channel (#express) and even the people there say that it is a major step to make. However, I think I'm getting the hang of it by what those people have told me.
One thing I'm struggling with.
Let's say. I create my page layout.
[code]
<html>
<head>
<title>Test</title>
</head>
<body>
My content
</body>
</html>
[/code]
Would I just use a .jade file to define the HTML in this way and instead of putting the content in manually generate it and replace a variable within the body tags? (in this example)
If that's the case, I think I get it...
[QUOTE=Cyberuben;45361406]Would I just use a .jade file to define the HTML in this way and instead of putting the content in manually generate it and replace a variable within the body tags? (in this example)
If that's the case, I think I get it...[/QUOTE]
You write your HTML in your templates. There should never be any HTML in your routes. You pass an object containing the values you want to be rendered to the template and render them in the template.
[QUOTE=supersnail11;45361464]You write your HTML in your templates. There should never be any HTML in your routes. You pass an object containing the values you want to be rendered to the template and render them in the template.[/QUOTE]
That's not what I'm saying.
However, I just found out you can make layouts extend something. But, that makes me wonder how I'd add a footer to a page.
layout.jade
[code]doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
[/code]
index.jade
[code]extends layout
block content
h1= title
p Welcome to #{title}
[/code]
So, what I don't seem to be getting: Does "block content" in "layout.jade" get replaced with "block content" in "index.jade", or is it appended to "layout.jade"? Then how would I add a footer? I mean, if it replaces, I would understand it, but if it appends, I'm not sure how I would do it.
[QUOTE=Cyberuben;45361802]That's not what I'm saying.
However, I just found out you can make layouts extend something. But, that makes me wonder how I'd add a footer to a page.
layout.jade
[code]doctype html
html
head
title= title
link(rel='stylesheet', href='/stylesheets/style.css')
body
block content
[/code]
index.jade
[code]extends layout
block content
h1= title
p Welcome to #{title}
[/code]
So, what I don't seem to be getting: Does "block content" in "layout.jade" get replaced with "block content" in "index.jade", or is it appended to "layout.jade"? Then how would I add a footer? I mean, if it replaces, I would understand it, but if it appends, I'm not sure how I would do it.[/QUOTE]
When you write "block content" without a body, you're telling it to put any content block you find (a "block content" with a body) into that spot. So if you wanted to place a footer, you could add another "block footer" without a body, and then add a "block footer" with a body to add a footer.
Okay, thanks for the helpful information!
[editline]12th July 2014[/editline]
Something else is bothering me.
Would it be bad to specify a line such as
[code]
div= contentOfDiv
[/code]
where contentOfDiv is a string generated by the file I'm currently in?
Let's say that I wrote some kind of mini web application that could be put in a div container, inside that div container is also some HTML.
I want to easily reuse it in a way that I could just leave an empty div block with certain id and it would fill up with proper HTML after page loads.
How is it done in a right way? Is it even right to hold lots of HTML in Javascript code?
[QUOTE=Cyberuben;45362250]Okay, thanks for the helpful information!
[editline]12th July 2014[/editline]
Something else is bothering me.
Would it be bad to specify a line such as
[code]
div= contentOfDiv
[/code]
where contentOfDiv is a string generated by the file I'm currently in?[/QUOTE]
I'm not sure what situation you'd run into that you'd need to do that.
[QUOTE=supersnail11;45362632]I'm not sure what situation you'd run into that you'd need to do that.[/QUOTE]
Well, lets say I retrieve blog posts from MySQL. How would I properly render these using jade then? A for loop and an array? Or what?
edit: I think I'm starting to understand it :v:
[editline]12th July 2014[/editline]
[QUOTE=suXin;45362619]Let's say that I wrote some kind of mini web application that could be put in a div container, inside that div container is also some HTML.
I want to easily reuse it in a way that I could just leave an empty div block with certain id and it would fill up with proper HTML after page loads.
How is it done in a right way? Is it even right to hold lots of HTML in Javascript code?[/QUOTE]
Using jQuery.load()? Or is that not what you mean?
[QUOTE=Cyberuben;45362789]Using jQuery.load()? Or is that not what you mean?[/QUOTE]
'load' gets it from the server, while I want Javascript code itself to produce required HTML so it can work.
[QUOTE=Cyberuben;45362789]Well, lets say I retrieve blog posts from MySQL. How would I properly render these using jade then? A for loop and an array? Or what?
edit: I think I'm starting to understand it :v:
[editline]12th July 2014[/editline]
Using jQuery.load()? Or is that not what you mean?[/QUOTE]
Pass an array of objects retrieved from the database and use an each statement. For example
[code]
each post in posts
span.title= post.title
p.body= post.body
[/code]
what's the best and also cheapest vps? i recall there being some host w/ fp ties that was hella cheap for semi-decent stuff
[QUOTE=ifaux;45364403]what's the best and also cheapest vps? i recall there being some host w/ fp ties that was hella cheap for semi-decent stuff[/QUOTE]
[URL="http://afterburst.com/"]Afterburst?[/URL] They also have a 25% off right now to celebrate 4 years.
[url]http://afterburst.com/[/url]
[url]http://ramnode.com/[/url]
Run by Fizzadar and Darksoul69, respectively.
I use DigitalOcean and it does whatever I need. You also pay per hour, so if you decide to use your VPS for three days and cancel it after, you won't have to pay the full month.
What's the fastest, most customizable (allows CSS editing at the very least), and cheapest eCommerce software? I know this is kind of a "pick two" situation, but reccomendations would be nice.
[QUOTE=jetboy;45364421][url]http://afterburst.com/[/url]
[url]http://ramnode.com/[/url]
Run by Fizzadar and Darksoul69, respectively.[/QUOTE]
darksoul69 doesn't run RAMNode
[QUOTE=Banana Lord.;45366935]darksoul69 doesn't run RAMNode[/QUOTE]
He does, or at least he did previously (I got a ticket with him), on the support team.
[QUOTE=Coment;45367032]He does, or at least he did previously (I got a ticket with him), on the support team.[/QUOTE]
Nope, he never ran it. He used to do support.
ty yall :')
[QUOTE=Banana Lord.;45367046]Nope, he never ran it. He used to do support.[/QUOTE]
I'm pretty sure he did. Does he not run Elpis and RamNode?
[QUOTE=jetboy;45368269]I'm pretty sure he did. Does he not run Elpis and RamNode?[/QUOTE]
He never ran RAMNode but he was a "high-level tech" there. He does, however, own/run Elpis.
I'd like to start getting into web hosting that's more than just "drag-and-drop files to the server" - do you guys have any good tutorials and starting points and the like?
[QUOTE=biodude94566;45369993]I'd like to start getting into web hosting that's more than just "drag-and-drop files to the server" - do you guys have any good tutorials and starting points and the like?[/QUOTE]
You can try out [URL="http://heroku.com/"]Heroku[/URL]. It supports most modern web languages (and also [URL="https://devcenter.heroku.com/articles/getting-started-with-php"]PHP[/URL]), and everything is handled through Git. Just run through their [URL="https://devcenter.heroku.com/articles/quickstart"]quickstart guide[/URL] and you'll figure it out pretty fast. Heroku's also awesome because you get 2TB of bandwidth free (and that's a soft limit) and an unlimited amount of free apps.
[QUOTE=supersnail11;45370176]You can try out [URL="http://heroku.com/"]Heroku[/URL]. It supports most modern web languages (and also [URL="https://devcenter.heroku.com/articles/getting-started-with-php"]PHP[/URL]), and everything is handled through Git. Just run through their [URL="https://devcenter.heroku.com/articles/quickstart"]quickstart guide[/URL] and you'll figure it out pretty fast. Heroku's also awesome because you get 2TB of bandwidth free (and that's a soft limit) and [B]an unlimited amount of free apps[/B].[/QUOTE]
Isnt it just 1 per account?(free)
i'm diving headfirst into a vps - any suggestions as to which one i should purchase from ramnode for personal hosting & low traffic websites? i'm looking at either the 128mb CVZ or SVZ - the former comes w/ 80gb & the latter 10gb - what is the difference here
[QUOTE=Richy19;45370555]Isnt it just 1 per account?(free)[/QUOTE]
One dyno per app, but an unlimited amount of apps. They limit you to five until you give them a card, but they don't charge you if you stay at one dyno per app.
ps sorry if i sound dumb. i've never been the behind the scenes server guy behind the stuff i've done that actually made it far enough to require a server
[editline]12th July 2014[/editline]
fucker broke my automerge
Sorry, you need to Log In to post a reply to this thread.