On installing Coffee Script on Node.js, we can get entry to the coffee-command line utility. In here, the coffee command is the important command. Using various options of this command, we are able to bring together and execute the Coffee Script documents.
You may see the list of alternatives of the coffee command using its -h or --assist choice. Open the Node.js command prompt and execute the following command in it.
This command gives you the list of various options of the coffee, along with the description of the operation performed by each of them as shown below.
The Coffee Script files are saved with the extension .coffee. You can compile these files using the -c or --compile option of the coffee command as shown below.
Suppose there is a file in your system with the following CoffeeScript code which prints a message on the console.
note − The console.log() function prints the given string at the console.
To assemble the above code, save it in a record with the name sample. Coffee. Open the Node.js command activates. Browse through the route wherein you have got saved the document and bring together it the usage of the -c choice of the coffee command of the coffee command-line application as proven under.
On executing the above command, the CoffeeScript compiler compiles the given file (sample.coffee) and saves it in the current location with a name sample.js as shown below.
You can execute a CoffeeScript file by simply passing the file name to the coffee command in the Node.js command prompt as follows.
As an instance, let us execute the sample. Coffee document. For this, open the Node.js command prompt. Browse through the direction wherein you have got stored the file and execute the file by immediately passing its name to the coffee command as shown underneath.
In a few scenarios, there may be a chance that we do a variety of adjustments to our scripts. the usage of the –w option of the coffee command, you watch your scripts for adjustments.
You may watch and collect a report simultaneously using the -WC choice as shown under. while we use this option, the record will be recompiled every time you make changes in your script.
Assume we've compiled a record named sample.coffee the use of the -WC option and we modified the script three times. On every occasion we exchange the script, the .coffee file is recompiled leaving the Node.js command prompt as shown below.
Coffee Script offers you a REPL-interactive shell. This shell is used to evaluate the Coffee Script expressions. You may type any Coffee Script code in this shell and get the result without delay. You can open REPL by using executing the coffee command with none options as shown underneath.
Using this shell, we are able to assign values to variables, create functions, and evaluate outcomes. As shown in the following screenshot, if we call capabilities in REPL, it prints the price of the function. If we give an expression to it, it evaluates and prints the end result of the expression. And if we in reality kind the statements in it, it prints the cost of the closing declaration.
In REPL, you could access more than one line mode with the aid of pressing ctrl+v wherein you can evaluate the code with a couple of traces (like capabilities) and you can get back to REPL mode from it by way of pressing ctrl+v again. Here is an example usage of the multi-line mode.
However, for this, we should import the library in every application and the CoffeeScript code might be interpreted line by line earlier than the output is shown. this could gradual down your packages, therefore this method isn't always recommended.
CoffeeScript Related Interview Questions
|XML Interview Questions||HTML Interview Questions|
|HTML 5 Interview Questions||Oracle DBA Interview Questions|
|HTML DOM Interview Questions||Java Interview Questions|
|JBOSS Interview Questions||Java XML Interview Questions|
|ebXML Interview Questions||Unix/Linux Interview Questions|
|Xml Publisher Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.