Is there a way I can render if I add an index.php
We have a couple of experimental projects which do work and allow you to use PHP, but it’s unsupported for now: https://glitch.com/edit/#!/lamp-poc and https://glitch.com/edit/#!/php-poc
I’m new on glitch. I’ve used php for years. Now that glitch.com doesn’t support php I tried learning Nodejs . But W3C thoroughly confused me! When I access the nodejs file which is scripts.js, the server doesn’t render it at all. Please help
Please share your project name so we can take a look.
I am not much familiar with node JS and quite honestly, a bit confused about what nodeJS exactly. A Server side scripting language or a server in itself.
Hi @jeet-patil
I would say that Node is a server-side scripting language, but it depends on what you mean with “scripting language”. Perhaps it is less ambiguous to say the Node is a server-side runtime that executes code written in JavaScript. Looking at your project, for example, the content of script.js
seem to be written for Node:
var http=require('http');
http.createServer(function server(req,res){
res.write("This is teresa information charlie");
res.end();
}).listen(80);
So this script creates an http server that listens on port 80. Now let’s understand why it is not working for you:
-
Your project does not have a
package.json
. Glitch checks some key files in your repository to understand which kind of project you want to start. If it finds a package.json file, Glitch thinks you are writing a Node application, otherwise it just starts a static web server. The difference is of course that with a static web server you can’t have any script running on the server-side. So if you create a new project of type “Node app” you can copypackage.json
from there and bring it in your project, as a starting point. Glitch will turn your app into a Node app. -
You instructed the http server in script.js to start listening on port 80, which is not available. You should use
process.env.PORT
instead. -
The http server you created always respond the same to any http request you send at him. You probably want something more complex. Again, have a look at the code of the new project of type Node app for more information, or look up a tutorial about express or Node http servers in general. Or ask again here
Having that said, if you want to realize a website and not a web application, that is, if you don’t need to have any server-side code running, you are better off with not using package.json
. In this case, all the files in your project will only be executed on the client-side, the browser.
Thanks a lot. I tried the same. But my website immediately stopped working!
logs:
node v6.13.1, with pnpm
Installing…
Previous installation was done with node v9, recreating node_modules
Packages: +49
+++++++++++++++++++++++++++++++++++++++++++++++++
dependencies:
- express 4.16.3
Total install time: 9794ms
node v9.8.0, with pnpm
Installing…
Previous installation was done with node v6, recreating node_modules
Packages: +49
+++++++++++++++++++++++++++++++++++++++++++++++++
dependencies:
- express 4.16.3
Total install time: 10900ms
/etc/app-types/node/start.sh: line 33: file.js: command not found
Here is the package.json:
{
“//1”: “describes your app and its dependencies”,
“//2”: “https://docs.npmjs.com/files/package.json”,
“//3”: “updating this file will download and update your packages”,
“name”: “my-glitch-app”,
“version”: “0.0.1”,
“description”: “What am I about?”,
“scripts”: {
“start”: “file.js”
},
“dependencies”: {
“express”: “^4.16.3”
},
“engines”: {
“node”: “9.x”
},
“repository”: {
“url”: “url to my app”
},
“license”: “MIT”,
“keywords”: [
“node”,
“glitch”,
“express”
]
}
You’ve to set a valid start script, right now it is file.js
, it should be node file.js
or something like that.
I try once again. Thanks
Hey @jeet-patil!
If @etamponi’s solution doesn’t fix the error(s), make sure you named your file correctly. If the file name in your package.json
file isn’t the same as your actual file name then it will give an error saying it can’t find it.
As for the file @Crazy , I’ve named it correctly
Now I get this error:
node v9.8.0, with pnpm
Installing…
Total install time: 5835ms
module.js:545
throw err;
^
Error: Cannot find module ‘/app/file.js’
at Function.Module._resolveFilename (module.js:543:15)
at Function.Module._load (module.js:470:25)
at Function.Module.runMain (module.js:690:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:666:3
module.js:545
throw err;
^
Error: Cannot find module ‘/app/file.js’
at Function.Module._resolveFilename (module.js:543:15)
at Function.Module._load (module.js:470:25)
at Function.Module.runMain (module.js:690:10)
at startup (bootstrap_node.js:194:16)
at bootstrap_node.js:666:3
I’m sorry but what should this node file.js contain?
This error appears when your main file isn’t named the same in your package.json
file. Your package
file should look like this (let’s assume your main file’s named server.js
):
"main": "server.js",
"scripts": {
"start": "node server.js"
}
I see @Crazy, but should this file contain some specific code?
Not right away, no. It shouldn’t give any errors if empty and the package.json
file is looking for the correct file.
I get it. But no success so far. I’m trying…
Mind sending the project link? I can take a look at it.
sure.
Ah, I see the issue. You added ‘node’ in the file.js
name. Node is the service being used to write and host your JavaScript. In the script in the package.json
file we add node
before the file name because that’s how you run a file with Node.
So to fix this issue just rename the file to file.js
and remove the node
.
I get it. I’m trying now
@Crazy .No errors so far…
Alright, it should work then! I would recommend adding the string below above your "script"
just so that you package file knows that file.js
is your main file.
"main": "server.js",
And if you have any other questions about Node[.js] you can go here or look up tutorials on YouTube! There are tons of places where you can learn how to use it for free.
Ok. I get it. No errors in the logs. But my site is still stuck. It won’t start!
I’m not entirely sure how to make the site load and still have the index.html
page show up, but you can get it to load with a package called Express below.
I’ll take a look at that.
NodeJS is easy, you should try learning lua first, its easier and nodejs is highly similar to it
this thread went off track, and did not really answer the question so ill have to assume the answer to is this got a php module installed to use php here is no. why not just say no php is not supported here. or yes you may use php. php is a very powerful way for your browser to talk to and operate for your nodejs projects. i would rather php than use javascript as it hides a lot more of the access to your data etc which is why we are useing nodejs in the first place.id love to present my combo chatbot baduk ai here.
The answer is PHP works, but is not supported.
i suppose i could host the php part at hostzinger and have it access the nodejs part of the node host here, which is like i have it on my tablet. cause the slim way just doesn’t turn my crank.
ah ty for the quick response. ill try the way i suggest then. the page does not need to be the same host anyway.
you rock riverside rocks!
I am happy to see that you are getting assisted, but please refrain from bumping topics.
Hi,
can U tell me if this version of Glitch :・゚✧ php has support for metods GET and POST?
Please make a new topic for this question.
Yes, it does ($_GET and $_POST)