Querying for the weather
We will make use of Node.js to query for the weather information using Google’s unofficial weather API. It will be a simple command line script.
There are a variety of ways to install Coffeescript. Let’s make use of package.json to install our packages. You could add Coffeescript to your list of dependencies in package.json
1 2 3
to install it. If not you can install it directly with npm.
You can also install it via your package manager. Most of them should provide a Coffeescript package.
That will output a foo.js.
Once you have a lot of Coffeescript files, compiling by hand becomes tedious. Currently many open source Node.js projects prefer to use GNU Make. You can make use of make to compile your Coffeescript files into Javacript. Below is an example.
Save the script as Makefile. This compile taget assumes three things. One, your Coffeescript files are under the src directory. Two, your coffee executable is found under node_modules. Three, you want your compiled Javscript files to be saved under the bin directory. Do replace if otherwise. Currently the convention is to put the Coffeescript files under the src directory. And then compile to the lib or bin directory. You can compile all your Coffeescript files by running the command below.
The compiled files can be found under the bin directory.
Automating the compilation
As you develop the code, you will find the process of compilation tedious. There are ways to automate the compilation.
Below is a sample Guardfile that watches Coffeescript files for changes and compiles them.
1 2 3
Compile on run
You can run the following to see the results.
The only caveat is you cannot pass arguments to the script elegantly. There is a workaround though.
Using Coffeescript to develop your Node.js project is simple. Simply setup your project to compile your source and that is it.