Jump to content

Recommended Posts

In a tutorial for Node.js that i was reading(http://www.nodebeginner.org/), i have put this code in helloworld.js(as the tutorial told me):

console.log("Hello World")

and tried to let it work by opening Node.js and typing node helloworld.js, but it have done nothing but made a new line with 3 points like this: . . . , i also tried % node helloworld.js,it had to inout Hello World in node.js, but it have done nothing but the new line with the 3 points.Please help.

Edited by Rotinomx
Link to post
Share on other sites

Opened a text editor which is notepad, wrote the code:

console.log("Hello World")

and saved it as helloworld.js.Then i opened node.js,which i have downloaded already, and wrote node helloworld.js to run it then pressed enter,it just got to a new line with three points, and the code never runs.That's what i have done according to http://www.nodebeginner.org/

Link to post
Share on other sites

What do you mean you open node.js? The command "node helloworld.js" is what you should be typing on the command line to execute node and tell it to run that file. You don't open node.js first, then run that command, the one command will run node and tell it which file to execute. You type that command into your operating system's shell or console.

Link to post
Share on other sites
The book says
right, as in (osx for example)
$ node helloworld.js

other than through the terminal, im not sure how else you could have done it ("opening" node.js)

Edited by thescientist
Link to post
Share on other sites
http://en.wikipedia.org/wiki/OS_X as opposed to the command prompt for windows. it would be the same either way, but the interfaces are different, and wasn't sure what OS you are using.
Link to post
Share on other sites

I tried it in command prompt, i typed node command,and then when i type hey.js that code appeared: C:\Users\theuser>node> helloworld.jsReferenceError: helloworld is not defined at repl:1:2 at REPLServer.self.eval (repl.js:111:21) at Interface.<anonymous> (repl.js:250:12) at Interface.EventEmitter.emit (events.js:88:17) at Interface._onLine (readline.js:199:10) at Interface._line (readline.js:517:8) at Interface._ttyWrite (readline.js:735:14) at ReadStream.onkeypress (readline.js:98:10) at ReadStream.EventEmitter.emit (events.js:115:20) at emitKey (readline.js:1057:12)>Does that mean that it didn't fine helloworld.js on my computer?

Link to post
Share on other sites

Oh,i got why,my command prompt only reads files at the user folder i which is 'theuser' which is an alt of my user name because i didn't want to reveal it.When i put helloworld.js in this folder,it worked,so how do i make the command prompt read the file in my desktop not in user folder?

Link to post
Share on other sites

prefix the the filename with the path to the desktop, i.e for (osx)

$ node /Users/yourusername/Desktop/helloworld.js

although for organization sake, it may be more practical to have a dedicated folder in your username or Documents folder, for each project you make.

Link to post
Share on other sites

After learning some of node.js, i have got a question in mind, will javascript(using node.js) be as good as php as a server-side scripting language.Will it be able to:respond to forms?Access database?Make forums, chats and other web apps?And how would i use it to respond to an html form,let's say that's the form:

<html><head><title>Form<title></head><body><form method="post"><input type="text" name="username" id="usr"><input type="password" name="pass" id="pwd"><input type="submit" value="submit"></form></body></html>

Do i need to add

action="respond.js"

to it, while executing it from node.js and add some code to respond.js,and what will that code be.Sorry, noob question.

Link to post
Share on other sites
will javascript(using node.js) be as good as php as a server-side scripting language.
That's fairly subjective. Node has features that PHP does not. I haven't investigated it thoroughly.
Will it be able to:respond to forms?Access database?Make forums, chats and other web apps?
According to the book you linked to, yes.
And how would i use it to respond to an html form,let's say that's the form:
I recommend you keep reading the book, that's what it's there for. With Node you basically create your own HTTP server, request routers, and request handlers. You don't need to link to Javascript files, you link to URLs which you use Node to specify how they should be routed and handled.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...