3

When I try to run the following coffeescript code:

request = require('request')
request('http://google.com', (error, response, body) ->
    if not error and response.statusCode is 200
        console.log(body)
)

I get the following error:

request('http://google.com', (error, response, body) ->
                                                      ^
SyntaxError: Unexpected token >
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:901:3

But when I run it on the coffeescript.org's compiler, it spits out the correct javascript. Any idea what's going on?

2
  • possible duplicate of Can I use CoffeeScript instead of JS for node.js? Commented Jul 12, 2013 at 9:02
  • Looks like you're running the coffeescript in node.js without compiling it? How did you start it? Commented Jul 12, 2013 at 9:03

1 Answer 1

3

When I looked for coffeescript's version on the terminal, it couldn't find it. So I exported coffescript's path by adding the following line to bashrc:

export PATH=/usr/local/share/npm/lib/node_modules/coffee-script/bin/:$PATH

This resolved the issue

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.