4 Replies - 256 Views - Last Post: 23 August 2018 - 06:24 AM

#1 Pogaca   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 128
  • Joined: 24-August 13

Node.js start

Posted 23 August 2018 - 02:26 AM

Greetings everyone. I started learning node.js . I downloaded instaler from their website and install all. Now, when I write js script, put it in same nodejs folder inside Program Files and try to run with node , it says error syntax. Image:

Posted Image

Now, maybe I made mistake here. But people suggested to use CMD for this, so I did it like this:

Posted Image

Again it doesn't work. Does anyone have a clue why is this happening?

Is This A Good Question/Topic? 0
  • +

Replies To: Node.js start

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4217
  • View blog
  • Posts: 13,329
  • Joined: 08-June 10

Re: Node.js start

Posted 23 August 2018 - 02:46 AM

does the command node -v work?
Was This Post Helpful? 0
  • +
  • -

#3 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2647
  • View blog
  • Posts: 4,228
  • Joined: 21-June 11

Re: Node.js start

Posted 23 August 2018 - 05:42 AM

When you're inside the node shell (as in your first screenshot), you can enter Javascript code and Node.JS will execute it and show you the resulting value if you entered an expression. node hello.js is not Javascript code, so you can't enter it into the node shell.

In your second screenshot you're in the command prompt. Here you can enter node hello.js (assuming node is in the %PATH% and a file named hello.js exists in the current directory. But you're not. You're entering what looks like a prompt followed by node hello.js. That's not valid syntax. If you want to execute a command in a different directory, you should just cd into that directory before running the command - you can't just enter pathname> before the command.

This post has been edited by sepp2k: 23 August 2018 - 05:43 AM

Was This Post Helpful? 0
  • +
  • -

#4 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7263
  • View blog
  • Posts: 15,142
  • Joined: 16-October 07

Re: Node.js start

Posted 23 August 2018 - 06:10 AM

In your first screen shot, you're in the node interpreter. Try typing .help, btw.

In the second, a command line: good. Note that in the C:\Program Files\nodejs folder there should be a file nodevars.bat. From that command line, execute nodevars.bat and then try node hello.js.
Was This Post Helpful? 0
  • +
  • -

#5 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7263
  • View blog
  • Posts: 15,142
  • Joined: 16-October 07

Re: Node.js start

Posted 23 August 2018 - 06:24 AM

Since I happen to have a windows box at work with node, I did this quick test:
PS C:\Users\baavgai> node -v
v8.9.1
PS C:\Users\baavgai> "console.log('hello node');" | Out-File -FilePath foo.js -Encoding ascii
PS C:\Users\baavgai> node .\foo.js
hello node
PS C:\Users\baavgai> node 'C:\Users\baavgai\foo.js'
hello node
PS C:\Users\baavgai>



Note that if you want full path with C:\ or spaces you'll want to quote that path.

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1