How do you set up a nodejs project on repl.it? I have a project that works on my localhost but once I uploaded it to repl.it it stopped working. Does repl.it automatically install packages from your package.json file? Is there something specific to my project that breaks it? Here is my code https://repl.it/#awestover/theland
The index.js script begins to run (I have a console.log in it) but the site just says, Cannot GET /
Is this because my index.html is in the wrong place?...
Thanks for any help!
I figured out the problem. I forgot to upload my index.html file so there was nothing to serve as the default site. Thanks for your help!
I suspect you missed something when you copy-pasted it onto Repl.it. You don't have any GET routes for /, which is why it's breaking with the message that it is.
Yev from Repl.it here, if you go to all languages and then select Node.js, you should be able to start up a node.js repl that way. Or, if you prefer the straightaway link, here it is
https://repl.it/languages/nodejs
Related
I had a Traversy Media tutorial on how to learn the MERN stack that I was following. I had the first part installed on my desktop and it was working properly. opened it back after two weeks and I am getting '/Users/mohamedsoliman/Desktop/Traversy Media/backend/server.js'
the problem here is that the folder structure should have a "backside folder" so server.js should be at "'/Users/mohamedsoliman/Desktop/Traversy Media/backend/backside/server.js'"
Not sure how can I fix this or if that's the only problem I have here ?
This image shows the directory structure I have for the project
This image shows the error I am getting
Your code is currently nodemon backend/server.js, but it should be nodemon backend/backside/server.js.
It looks like your server.js is your entry point for the app.
In that case, run the app as follows,
node backend/backside/server.js
First i got the following error and i couldn't figure yet what is this about:
any idea?
The problem is that you're trying to open an HTML file with Node.js.
Node.js is supposed to run JavaScript code (typically stored in .js files) and it cannot parse your HTML file, which is why you're getting these errors.
You could try executing the files called app.js or server.js with the following commands:
node app.js
or
node server.js
Also, it seems your project (or whatever it is you're working on) has a README.md file which could help to clarify where you're supposed to start.
I have tried the related solutions for this problem (eg. add the dependencies through 'package.json' and run npm install) but unfortunately they didn't solve it. Problem is when I run the code from the accepted answer from the following discussion:
Node.js, Ajax sending and receiving Json
everything works fine. the Ajax-call works and I get the result with the data. But in the console I get the error.
'ReferenceError: Can't find variable: require' (Globale code — requesthandle.js:2ReferenceError: Can't find variable: require)
Any ideas which could be the problem here? Thank you!
This is the code I am using:
requesthandle.js (server side, by executing node requesthandle.js) ==>
http://i67.tinypic.com/24zbyma.png
and
list.html (by visiting mydomain/list.html)
http://i65.tinypic.com/mwp3md.png
Found the solution.. overlooked the fact I included the requesthandle.js in my list.html / client-side code. Thank you for your help Arpit Solanki! Seems your first remark included the solution: I was using it frontend by mistake..
Im try to do the React JS tutorial and im trying the server in node. I downloaded first, all files in https://github.com/reactjs/react-tutorial/ then I put in folder then I command prompt it. and type npm install then node server.js "Server started: //localhost:3000./
Then when I go to the localhost:3000.is said Cannot Get/ .
What's the problem?
Are you entering localhost:3000 without a period?
If you wish to learn React JS. Please install on the local machine and related module like node JS, etc.
Please have look below link for your review. May be it will help you.
React JS – Install and Setup
I've just started with node.js and socket.io.
I installed node.js using the windows installer, resulting in the following install path:
C:\Program Files (x86)\nodejs
I used npm to install socket.io and managed to include this in my server file, which is located in my projects folder, under
D:\projects\node\nodeserv.js
I then included the socket.io.js, which is located under the same socket.io folder, under the nodjs folder.
However, when I try to open the HTML file containing the client code, I get an error in socket.io.js stating:
Undefined reference to 'require'
Can someone help me out and see what I am doing wrong?
Make sure to check your spelling very carefully. If you can post post some code to look at, we can probably tell you the problem right away. More than likely it's a simple typo.
It sounds like you are trying to run node.js from the browser. Node.js runs on the server with the node executable. When you open the HTML file in your browser, it will execute the Javascript on it in a non node.js environment.
Apparently you need to get the socket.io.js file from the nodejs server.
So instead of an include, use an async call to get the file, like:
$.getScript('http://localhost:1337/socket.io/socket.io.js', function(){
//You can now use the io namespace
});