Here are a few tips on how to build a simple node. js application.
Build node. JS Services from scratch
Build a Node.js+express.js Service
Build a simple node. js + express.js + handlerbars service from scratch
Build node. JS Services from scratch
Excerpt from node for learning
Code is as follows:
$ node var http = require (' http '); > Http.createserver (function(req, res) { Res.writehead, {' Content-type ': ' Text/plain ' }); Res.end (' Hello world\n ');}). Listen (8124, "127.0.0.1");
- Start node first.
- You can define an HTTP server on the command line.
Build a Node.js+express.js Service
1. Installing Nodejs
2. Installing Express.js
NPM Install-g Express
NPM install-g Express-generator
Express Testexpress
CD testexpress
NPM Install
Node app
This allows you to install a jade as a template application.
build a simple node. js + express.js + handlerbars service from scratch
Original video link: http://vimeo.com/91564681
Ignoring the description of Git is summarized below.
0. Create a directory
mkdir Node-express-handlebars
1. NPM Install
CD Node-express-handlebars
NPM Install
/* Accept all the default configurations. */
2. Install Express
NPM Install Express--save
3. Installing Express-handlebars
NPM Install Express-handlebars--save
4. Create a Server.js
varExpress = require (' Express ');varApp =Express ();varExhbs = require (' Express-handlebars ')); App.engine (' Handlebars ', Exhbs ({' defaultlayout ': ' Main '}); App.set (' View engine ', ' handlebars '); App.get (‘/‘,function(req, res) {varLucknumber = Math.Round (Math.random () * 10); Res.render (' Index ', {lucknumber:lucknumber});}); App.use ('/public ', express.static (' Public '));varPort = number (Process.env.PORT | | 5000); App.listen (port);
5. Create a views directory
As shown below
Main.handlebars
<!DOCTYPE HTML><HTML><Head> <MetaCharSet= "Utf-8" /> <title>Example App</title></Head><Body>{{{body} }}</Body></HTML>
Index.handlebars
This is index.handlebarshellow there, your lucky number is {{Lucknumber}}
6. Run
Nodemon Server.js
NodeJS-1 building a simple node JS application