FAQ
Hello, I just finished installing nodejs on ubuntu. I wanted to do a simple
Hello World to get started so I executed the following at the command
prompt:

     node console.log('hello world')

However, this returns the following error:

     -bash: syntax error near unexpected token '('

Any idea what might be causing this issue and how to fix?

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/5cc45e76-2f39-46a4-950d-0f80e5cbf58a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Aria Stewart at Dec 29, 2014 at 3:10 pm

    On Dec 29, 2014, at 2:12 AM, noderiety wrote:

    Hello, I just finished installing nodejs on ubuntu. I wanted to do a simple Hello World to get started so I executed the following at the command prompt:

    node console.log('hello world')

    However, this returns the following error:

    -bash: syntax error near unexpected token '('

    Any idea what might be causing this issue and how to fix?

    Yes! You're actually mixing up two different things. The node command-line consists of a script to run, and arguments to pass to it, parsed by the shell -- the shell is what's giving you the error, because you're giving it javascript, not simple space-separated arguments like command-lines take. (you can do more, but quoting rules abound!)

    So what you want to do is put your one-line script in a file -- call it 'hello.js' perhaps, then:

    node hello.js

    It should print out "hello world"

    Aria

    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/44ED1D21-5F1E-4E76-AFE4-9B8F3A6B4AE7%40nbtsc.org.
    For more options, visit https://groups.google.com/d/optout.
  • Peter Petrov at Dec 30, 2014 at 1:05 am
    An alternative solution:

    echo "console.log('hello world')" | node

    On Monday, December 29, 2014 5:11:01 PM UTC+2, Aria Stewart wrote:

    On Dec 29, 2014, at 2:12 AM, noderiety <andrew.d....@gmail.com
    <javascript:>> wrote:
    Hello, I just finished installing nodejs on ubuntu. I wanted to do a
    simple Hello World to get started so I executed the following at the
    command prompt:
    node console.log('hello world')

    However, this returns the following error:

    -bash: syntax error near unexpected token '('

    Any idea what might be causing this issue and how to fix?

    Yes! You're actually mixing up two different things. The node command-line
    consists of a script to run, and arguments to pass to it, parsed by the
    shell -- the shell is what's giving you the error, because you're giving it
    javascript, not simple space-separated arguments like command-lines take.
    (you can do more, but quoting rules abound!)

    So what you want to do is put your one-line script in a file -- call it
    'hello.js' perhaps, then:

    node hello.js

    It should print out "hello world"

    Aria
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/795fdba7-c46d-42bf-a48b-07d6eddf140f%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Paul Spaulding at Dec 30, 2014 at 3:08 pm
    or, evaluate and print result:

    node -p "'hello world'"


    On Monday, December 29, 2014 2:12:56 AM UTC-5, noderiety wrote:

    Hello, I just finished installing nodejs on ubuntu. I wanted to do a
    simple Hello World to get started so I executed the following at the
    command prompt:

    node console.log('hello world')

    However, this returns the following error:

    -bash: syntax error near unexpected token '('

    Any idea what might be causing this issue and how to fix?
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/b163dc03-acb6-4fc9-8e46-8fef2ceeef3c%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Paul Spaulding at Dec 30, 2014 at 3:08 pm
    node -e "console.log('hello world')"


    On Monday, December 29, 2014 2:12:56 AM UTC-5, noderiety wrote:

    Hello, I just finished installing nodejs on ubuntu. I wanted to do a
    simple Hello World to get started so I executed the following at the
    command prompt:

    node console.log('hello world')

    However, this returns the following error:

    -bash: syntax error near unexpected token '('

    Any idea what might be causing this issue and how to fix?
    --
    Job board: http://jobs.nodejs.org/
    New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
    Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
    ---
    You received this message because you are subscribed to the Google Groups "nodejs" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscribe@googlegroups.com.
    To post to this group, send email to nodejs@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/5e672cf4-cbf4-4bec-9604-f386835087ad%40googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedDec 29, '14 at 3:01p
activeDec 30, '14 at 3:08p
posts5
users4
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2021 Grokbase