Parallax
Parallax7d ago

Is there a way to use Javascript as easily as Php?

Sorry for the vague title. I don’t know how else to say it. In Php, you can make a simple file that looks like this
<?php echo "Hello"; ?>
<?php echo "Hello"; ?>
When a user requests that file, it automatically executes the Php code and sends them the result, using https. Easy But whether using Node or Deno, it seems like you need to add lines and lines of code to set up a server… on your already running server… which makes no sense to me, but sure. I guess I can do that You also have to figure out a way for it to find your ssl certificate and key, which change at unpredictable times and have unpredictable filenames each time (at least for me). And you have to figure out a way to make it detect when those files expire and automatically hotswap them And you also have to daemonise each and every script you write, and manage them all somehow, making sure one of them didn’t just fail silently 7 months after you started its process (happened to me, still not sure why) I have been trying to move away from Php to Javascript for many years, and I have tried to solve all these obstacles in many different ways. I must be doing something wrong, because it should not be this hard. Is Deno only meant for supergeniuses who already know how to code every aspect of their own server from scratch, or is there a way to use it that ordinary web developers can comprehend?
21 Replies
marvinh.
marvinh.7d ago
Deno is not a server, but a JS runtime that can spawn multiple servers. I think the one liner you're looking for is this:
Deno.serve(() => new Response("hello"))
Deno.serve(() => new Response("hello"))
If a process fails it's usually because of a reason. In PHP each request is typically served in its own process so it doesn't matter if one of them dies. This is not true for JS servers where they all share the same process. This is mostly a fundamental difference in approaches in the different programming languages. If you're happy with PHP then there is nothing wrong with staying with PHP
nakasyou
nakasyou7d ago
Markdownのパースに失敗 Markdownのパースに失敗
Parallax
Parallax7d ago
I’m happy with the workflow of Php, but since i don’t touch the backend as much as the frontend, i’m always forgetting the particulars of how it works. I also find it hard to write clean-looking Php code. That’s kinda why i would like to use Javascript in both places. Will that serve it over https tho? And what do i have to do in addition to simply writing the file, in order to make it actually work?
marvinh.
marvinh.7d ago
if you pass it some certificates it will serve via https.
And what do i have to do in addition to simply writing the file, in order to make it actually work?
not sure what you mean by it. Calling deno run -A myscript.ts runs it
Parallax
Parallax7d ago
I can’t just create infinite terminal sessions and have them running deno processes XD
marvinh.
marvinh.7d ago
well how do you start your apache2 or nginx server in PHP? Do the same thing with Deno
Parallax
Parallax7d ago
And it still doesn’t fix my problem with ssl certificates. Does Deno not have any functionality that integrates certificates for you, instead of having to reimplement a search algorithm in every script? I don’t handle that. My hosting provider does it
marvinh.
marvinh.7d ago
Ah so you're looking for a hosting provider that has Deno pre-configured for you. Most folks with Deno use Deno Deploy https://deno.com/deploy
Parallax
Parallax7d ago
I can’t access your link. It looks like it’s behind a login screen
marvinh.
marvinh.7d ago
apologies fixed it, sent the wrong one
Parallax
Parallax7d ago
Oh, thanx Ouch. Deno Deploy’s cheapest option is six times as expensive as what i’m currently paying for hosting! And it doesn’t even have unlimited bandwidth! So… is this my only option? Is Deno simply unusable unless you use Deploy or unless you’re the administrator of your server? Am i the only person in the world who uses a generic hosting provider, and not some globally distributed cloud service that integrates with Github or something? Everything about Deno seems to be aimed at people who don’t need Deno because they’re already smart enough to code their own Javascript runtime from scratch in Assembly
marvinh.
marvinh.7d ago
Generic hosting providers is pretty common with PHP. They've specialized on that for many years. Again it sounds like you're really happy with PHP already. There is nothing wrong with sticking with that
UH
UH7d ago
Everything about Deno seems to be aimed at people who don’t need Deno because they’re already smart enough to code their own Javascript runtime from scratch in Assembly
Legit braindead
Parallax
Parallax7d ago
😟 If i was happy, i would not have come here I have been unhappy for a very long time, and i worked up the courage to finally ask a question here. But you guys are making fun of me just like everybody else in the programming community
aarvin roshin
aarvin roshin7d ago
@Parallax check out this video. there's nothing wrong with deno, and i don't think people are intentionally trying to make fun of you, if you're doing good with php it's absolutely fine to just stick with it. https://youtu.be/PqUjzXiDQ2A?si=TxcannguFtld5WsL
Theo - t3․gg
YouTube
New Tech Is A Trap (It Might Doom Your Career)
I'm tired of people assuming they have to learn all the new things or they will fall behind. It is BETTER to be late 99% of the time. Check out my Twitch, Twitter, Discord more at https://t3.gg S/O Ph4se0n3 for the awesome edit 🙏
aarvin roshin
aarvin roshin7d ago
there might be a time in the future where you reconsider learning deno, in which case the community is here to help 🙂
Parallax
Parallax7d ago
Thanks. I don’t think you understand my situation at all tho. I’m not trying to learn Deno because it’s new or because i’m afraid of falling behind. I just don’t like using Php. As a language, i like Javascript a lot more than Php, and i have known that for many years now. The “learning Deno” part is a non-issue. I have no problem with coding in Deno. I’ve made an instant messenger, a file hosting system, and a few other things with it. But actually implementing my apps in a stable sustainable way is what i’m struggling with. Sticking with Php is like a chore. It’s not ideal. But it’s what i have to do at the moment, because Node or Deno just don’t seem to have the basic functionality that Php has that allows you to make a simple file and have it be executed without any other setup. I’m very surprised that nobody can relate to me on this 🤔 Being a programmer means you’re basically an outsider in society. But i seem to be an outsider both in society and amongst programmers. At times like this, i emerge from my hiding place and resort to asking the community for help, but i don’t know why i thought that was a good idea, i should have known that the way i’m attempting to do things is so far off track from everyone else, and that no one has any actual suggestions in my case, other than to do the thing that i explicitly said i don’t want to do. Why do i keep doing this?
raunioroo
raunioroo6d ago
VPS servers are a nice, cheap middleground between administering your own server, and ready made cloud solutions. A bit more involved in setup than your typical php service,but not too bad. Cheapest option in AWS Lightsail is around 5 bucks a month, and works great with deno (unless your app is a memory hog, in which case you should look into the more expensive options with more RAM)
Parallax
Parallax5d ago
Thanks. I’ll look into it
Mr.Possumz
Mr.Possumz3d ago
I think part of the issue here is that PHP has a more limited scope and obscures a lot of what's going on behind the scenes. It's designed with one purpose in mind and that is serving pages, with tooling aimed at making it very easy to do exactly that. Deno, on the other hand, aims to be a viable option for a wider array of use cases. The result of that is the tooling and environment is more open ended. It can be (and very often is) used as a web server similar to PHP but it requires a little more effort to get off the ground. You'll need to research some of the JS frameworks and packages commonly used to accomplish this if you want to make the move. Try taking a look at https://fresh.deno.dev/, a web framework built specifically by the Deno team to run on Deno. It does run on deploy but can run in many other environments and I think it's server-side rendering is similar enough to PHP's that it should be easier for you to draw parallels
NeTT
NeTT2d ago
I remember Galaxygate having a $2 option. Oh it's $3 now