目录
1. 关于JavaScript
1.1 JavaScript 的历史
1.2 如何运行 JavaScript
1.3 JavaScript 的特点
2. 关于Node.js
2.1 Node.js简介
2.2 Node.js 的组成
1) V8 引擎
2) 本地模块
3) 标准库
3. 用Docker搭建和使用Node.js环境
FROM node:4-onbuild
EXPOSE 8888
'use strict';
var connect = require('connect');
var serveStatic = require('serve-static');
var app = connect();
app.use('/', serveStatic('.', {'index': ['index.html']}));
app.listen(8080);
console.log('MyApp is ready at http://localhost:8080');
$ npm init
This utility will walk you through creating a package.json file.
It only covers the most common items, and tries to guess sensible defaults.
See `npm help json` for definitive documentation on these fields
and exactly what they do.
Use `npm install <pkg> --save` afterwards to install a package and
save it as a dependency in the package.json file.
Press ^C at any time to quit.
name: (node) node
version: (1.0.0)
description: node-sample
entry point: (index.js)
test command:
git repository:
keywords:
author:
license: (ISC)
About to write to /Users/faxi/Docker/js/node/package.json:
{
"name": "node",
"version": "1.0.0",
"description": "node-sample",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Is this ok? (yes) yes
$ docker build -t node-image .
$ docker run -it -P node-image
npm info it worked if it ends with ok
npm info using npm@2.15.1
npm info using node@v4.4.3
npm info prestart node@1.0.0
npm info start node@1.0.0
> node@1.0.0 start /usr/src/app
> node server.js
MyApp is ready at http://localhost:8080
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7b6f666d4808 node-image "npm start" xxxago Up xx 0.0.0.0:32771->8888/tcp node-container
$ docker run -it --rm --name my-running-script -v "$(pwd)":/usr/src/myapp -w /usr/src/myapp node:0.10 node your-daemon-or-script.js