Can I use CoffeeScript instead of JS for node.js?
What are my restrictions if I want to code node.js and use CoffeeScript? Can I do anything I’d be able to do in JS? 8 Answers 8
What are my restrictions if I want to code node.js and use CoffeeScript? Can I do anything I’d be able to do in JS? 8 Answers 8
I have an object (an “associate array” so to say – also known as a plain JavaScript object): obj = {} obj[“Foo”] = “Bar” obj[“bar”] = “Foo” I want to iterate over obj using CoffeeScript as follows: # CS for elem in obj bu the CS code above compiles to JS: // JS for (i … Read more
Is there a null-safe property access (null propagation / existence) operator in ES6 (ES2015/JavaScript.next/Harmony) like ?. in CoffeeScript for example? Or is it planned for ES7? var aThing = getSomething() … aThing = possiblyNull?.thing This will be roughly like: if (possiblyNull != null) aThing = possiblyNull.thing Ideally the solution should not assign (even undefined) to … Read more
Please tell me how to write javascript below in coffeescript. setTimeout(function(){ something(param); }, 1000); 6 Answers 6
I have this simple script : var exec = require(‘child_process’).exec; exec(‘coffee -cw my_file.coffee’, function(error, stdout, stderr) { console.log(stdout); }); where I simply execute a command to compile a coffee-script file. But stdout never get displayed in the console, because the command never ends (because of the -w option of coffee). If I execute the command … Read more
On Coffeescript.org: bawbag = (x, y) -> z = (x * y) bawbag(5, 10) would compile to: var bawbag; bawbag = function(x, y) { var z; return (z = (x * y)); }; bawbag(5, 10); compiling via coffee-script under node.js wraps that so: (function() { var bawbag; bawbag = function(x, y) { var z; return … Read more
I need to set value to a that depends on a condition. What is the shortest way to do this with CoffeeScript? E.g. this is how I’d do it in JavaScript: a = true ? 5 : 10 # => a = 5 a = false ? 5 : 10 # => a = 10 … Read more
in the snippet like this: gulp.task “coffee”, -> gulp.src(“src/server/**/*.coffee”) .pipe(coffee {bare: true}).on(“error”,gutil.log) .pipe(gulp.dest “bin”) gulp.task “clean”,-> gulp.src(“bin”, {read:false}) .pipe clean force:true gulp.task ‘develop’,[‘clean’,’coffee’], -> console.log “run something else” In develop task I want to run clean and after it’s done, run coffee and when that’s done, run something else. But I can’t figure that out. … Read more
How do I use a local version of a module in node.js. For example, in my app, I installed coffee-script: npm install coffee-script This installs it in ./node_modules and the coffee command is in ./node_modules/.bin/coffee. Is there a way to run this command when I’m in my project’s main folder? I guess I’m looking for … Read more
I am trying to support CORS in my Node.js application that uses the Express.js web framework. I have read a Google group discussion about how to handle this, and read a few articles about how CORS works. First, I did this (code is written in CoffeeScript syntax): app.options “*”, (req, res) -> res.header ‘Access-Control-Allow-Origin’, ‘*’ … Read more