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.
Related
I have created a simple nodejs project to see how nodejs runtime execution flow works. In my project folder I have initiated a nodejs project with npm init -y command. Then added "type": "module" to the package.json file. After that I have created two files
index.js with following content
console.log("index.js")
import x from './test.js'
test.js with following content
console.log("test.js")
export default {}
When I tried to execute the index.js file with node index.js I got the result as follows
test.js
index.js
But I expected the otherway around. Could someone explain why this is the behavior I am getting. Also please advice me, is there any way to enforce nodejs to go through the index.js file first before the other one?
VScode error message saying shell integration not activated
Judging from your Screenshot:
The javascript file is located at ~/Documents/MY PROJECTS/hello.js.
You are trying to run a hello.js file in ~.
~ would be EDWIN in your case.
Since Node js can't find the hello.js file it throws an error. Locate the correct directory with cd Documents/MY PROJECTS and then try to run the js file via node hello.js
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
I am trying to get the meteor leaderboard app to run on Node-Webkit.
I have demeteorized it and compressed it to a .nw file but when I drop it in. I get errors:
Invalid Package There is no 'package.json' in the package, please
make sure the 'package.json' is in the root of the package.
I have read on various thread but nothing clear yet.
It seems like the demeteorized app needs to be restructured. Also need to figure out how to run the server [Locally/DDP].
Edited:
P.S. I am using the demeteorized files from the leaderboard meteor app to be able to run it in node-webkit.
What exactly I am trying to figure out here is :
how to run/init the local node(demeteorized) server and set the port.
How to set environment variables for the demeteorized app for mongodb etc.
What would be used as the
"main": ?,
"node-remote": ?
for the node-webkit package.json file.
Can someone please shed some light and if possible an example will be highly appreciated.
Thanks in advanced.
Praney :)
UPDATE:
After tinkering a bit, I added the "main": "index.html" and added index.html file to the root of the demeteorized app. This file just loads the main.js file in the browser, here:
<!DOCTYPE html>
<html>
<head>
<title>Leaderboards</title>
</head>
<body>
</body>
<script src="main.js" type="text/javascript"></script>
</html>
Now I am getting this error:
"Uncaught ReferenceError: __dirname is not defined", source:
file:///Users/Praney/projects/webkit/nw-sample-apps/leaderboards/main.js(2)
main.js
process.argv.splice(2, 0, 'program.json');
process.chdir(require('path').join(__dirname, 'programs', 'server'));
require('./programs/server/boot.js');
This isn't how demeteorizer is meant to be used.. exactly/kind of.
You would use the output bundle on your deployed server to run as your meteor app, not put it in an existing meteor app.
The package.json that you get from it is slightly different to the one that meteor-npm would use.
When you've finished your meteor app you would use demeteorizer to create an easy bundle that can run on your server. If you uploaded it and untarred it:
You would install the npm modules by cding into the bundle and running npm install
You can run the app as normal as described in the docs.
The whole purpose of demeteorizer is to nodify your app, you wouldn't need to this on the platform you made it since all the npm modules would already be working. The problem it solves is usually with cross-archs, e.g if you made your app on OS X and it uses binary npm modules and the server uses Ubuntu (not os x)
I suppose node-webkit could also do it, you would need to use the root directory of demeteorize for this (seperate from your app). You can see there's a package.json already in it, perhaps the root directory you set it to use is that of your meteor app and not the untarred output of the demeteorized app?
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
});