<== Previous Lesson Next Lesson ==>
<== Home 🏠
{ sitepoint.com/an-introduction-to-node-js
}
Check to see if Node is installed by opening a terminal and typing node -v
Next, create a new file hello.js
and copy in the following code:
console.log("Hello, World!");
This uses Node’s built-in console module to display a message in a terminal window. To run the example, enter the following command:
node hello.js
If Node.js is configured properly, “Hello, World!” will be displayed.
Open your terminal and type the following:
npm install -g jshint
This will install the jshint package globally on your system. We can use it to lint the index.js
file from the previous example:
jshint index.js
You should now see a number of ES6-related errors. If you want to fix them up, add /* jshint esversion: 6 */
to the top of the index.js
file, re-run the command and linting should pass.
We can also install packages locally to a project, as opposed to globally, on our system. Create a test
folder and open a terminal in that directory. Next type this:
npm init -y
This will create and auto-populate a package.json
file in the same folder. Next, use npm to install the lodash package and save it as a project dependency:
npm install lodash --save
Create a file named test.js
and add the following:
const _ = require('lodash');
const arr = [0, 1, false, 2, '', 3];
console.log(_.compact(arr));
Finally, run the script using node test.js
. You should see [ 1, 2, 3 ]
output to the terminal.
- F U R T H E R . R E A D I N G
- The Anatomy of a Modern JavaScript Application
{ .codefellows.org/blog/6-reasons-for-pair-programming
}
The Driver is the programmer who is typing and the only one whose hands are on the keyboard. Handling the “mechanics” of coding, the Driver manages the text editor, switching files, version control, and—of course writing—code. The Navigator uses their words to guide the Driver but does not provide any direct input to the computer.
The Navigator thinks about the big picture, what comes next, how an algorithm might be converted in to code, while scanning for typos or bugs. The Navigator might also utilize their computer as a second screen to look up solutions and documentation, but should not be writing any code.
<== Home 🏠