Objectives
- Understand the role Node plays in server side JS and list 3 differences from client side JS
- Define and describe npm
- Setup a node project directory
- Include core fs module in a program via require
Powered by:
NodeJS
# Search for packages related to V8
# Arch Linux
$ pacman -Ss v8
community/nodejs 6.3.1-1
Evented I/O for V8 javascript
NodeJS vs Browsers
- Runs as a standalone program
- Can start/stop/suspend
- Not tied to a parent program
- Access to things like screen brightness
- No DOM or other Browser Libraries
- No document object
- No window object
- No JQuery
- CommonJS Module System
- Use require to import a module
Node Package Manager
global vs. local installs
npm install http-server -g
npm install http-server
vs.
npm install -g typescript
installs to /usr/local
npm install gulp
installs to ./node_modules
Anyone Can Publish!
Project Setup
Project Setup
- Make folder
- Change to the folder (cd/pushd)
- Create your initial source file
- Initialize the package (npm init -y)
- Add a .gitignore file
- Add dependencies (if any)
package.json
The "manifest" for the package which contains
- Name
- Description
- dependencies
- License
- and much more
package.json
For more information see:
npm help 5 package.json
and
http://browsenpm.org/package.json
CommonJS Modules
Included in your program via require
"Encapsulates" code in re-useable units
CommonJS Modules
let fs = require("fs");
let path = require("path");
const log = console.log;
const inputFile = "data.json";
fs.readFile(inputFile,(err,data)=>{
if(err) {
throw err;
}
else {
log(data);
}
});
Objectives
- Understand the role Node plays in server side JS and list 3 differences from client side JS
- Define and describe npm
- Setup a node project directory
- Include core fs module in a program via require
Into To NPM and Node
By Matt Sprague
Into To NPM and Node
NodeJS Day 1
- 1,052