Sandbox
Last updated
Last updated
JavaScript on the server. Google's V8 engine. Node.js is an open-source, cross-platform runtime environment for developing server-side Web applications. Node.js is not a JavaScript framework, but its applications are written in JavaScript and can be run within the Node.js runtime on a wide variety of platforms, including FreeBSD, IBM AIX, IBM i, IBM System z, Linux, Microsoft Windows, NonStop and OS X. Node.js is used by GoDaddy, Groupon, IBM, LinkedIn, Microsoft, Netflix, PayPal, Walmart, and Yahoo!. Node.js is typically used where light-weight, real-time response is needed, like communication apps and Web-based gaming. It is used to build large, scalable network applications. Runs with a single thread in a process, no blocking I/O, asynchronous model.
CapabilitiesNode is a platform for writing JavaScript applications outside web browsers. This is not the JavaScript we are familiar with in web browsers!. There is no DOM built into Node, nor any other browser capability. Beyond its native ability to execute JavaScript, the bundled modules provide the following capabilities: Command-line tools (in shell script style) Interactive-TTY style of program (REPL or Read-Eval-Print Loop) Excellent process control functions to oversee child processes File system access *Built-in rudimentary unit testing support through assertions
To start watching NPM in action, let's first create a package.json file. This file serves as a local package manifest, contains JSON (an object serialization format that is a subset of JavaScript), is placed at the root of your application folder and is, among other things, where you can declare what NPM modules your application depends on.
It's very easy to write an HTTP server in Node, but the typical web application developer doesn't need to work at that level of detail. Open a simple text editor such as nano or vim, and copy & paste the code below and save it in a server.js named file. var http = require('http'); http.createServer(function(req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello World\n'); }).listen(8124, "127.0.0.1"); console.log('Server running at ');
To run the server, type node server, node should open in the specified port.
Status:Creating the server, since the way is creating is a full example, I'm creating a fit example, will delay a day or two to upload every step and finished code.
The MEAN stackGenerating a Node server with Express
Is a web app framework for Node Http server Routes Middleware Create a working directory with
mkdir ExpressTest
and switch to itcd ExpressTest
. Install express globally withnpm install -g express
andnpm install -g express-generator
. Generally, we install npm modules withnpm install <name_of_the_module>
, but to install packages globally use the-g
flag. Generate a server usingexpress
in the current directory ofExpressTest
. This will generate a full node server with routes and http methods.
Alternatives
Node-REDNode-RED is a tool for wiring together hardware devices, APIs and online services in new and interesting ways.
PrerequisitesNode.js already installed. For Linux/OS X, if you already have Node.js installed, run: $ sudo npm install -g node-red $ node-red
Cylon.js is a JavaScript framework for robotics, physical computing, and the Internet of Things. It makes it incredibly easy to command robots and devices.
All you need to get started is the cylon NPM module:
npm install cylon