Node.js
Harness the power.
The Facts
- Node.js is an event driven I/O framework
- Node.js is built for the V8 JavaScript engine (Which is what Chrome uses)
- Node.js is fast
- Node.js is JavaScript running on a server
A simple web server
// This loads the http module var http = require('http'); // This configures our http server var server = http.createServer(function (request, response) { // Called once the server has started
response.end() }); // Listen on port 3000, IP defaults to 127.0.0.1 or localhost server.listen(3000); // Log what is happening, so we can see it in terminal console.log("Server running at http://127.0.0.1:3000/");
Including files
- Node.js uses the require standard for including files
var myLibrary = require('./mylibrary')
included file example
module.exports = function(){
console.log('Hello from My Library!')
};
Express.js
- Express is a library for Node.js
- Express handles routing, rendering, and app configuration
- Type "express" in terminal to instantiate the Express bootstrap
Routes
//When I go to my root domain in the browser, render the index view
app.get('/', function(req, res){
res.render 'index'
});
NPM
- NPM is the online repository for sharing node modules
- `npm install` - installs files from package.json. These files are pulled from the Node Packaged Modules system
Node.js
By Matt Null
Node.js
- 1,494