Node.js サンプル
Table of Contents
例
recipe_connection
$ mkdir recipe_connection
$ cd recipe_connection/
$ 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: (recipe_connection) ls -la Sorry, name can only contain URL-friendly characters. name: (recipe_connection) version: (1.0.0) description: An app to share cooking recipes entry point: (index.js) main.js test command: git repository: keywords: author: wurly license: (ISC) About to write to /home/wurly/node/recipe_connection/package.json: { "name": "recipe_connection", "version": "1.0.0", "description": "An app to share cooking recipes", "main": "main.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "wurly", "license": "ISC" } Is this ok? (yes) yes
$ npm install cities --save recipe_connection@1.0.0 /home/wurly/node/recipe_connection mqw cities@2.0.0 tqq haversine@1.1.1 mqq lodash@4.17.21 npm WARN recipe_connection@1.0.0 No repository field.
simple_server
$ mkdir simple_server
$ cd simple_server/
[wurly@mozuku simple_server]$ 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: (simple_server) version: (1.0.0) description: simple server entry point: (index.js) main.js test command: git repository: keywords: author: wurly license: (ISC) About to write to /home/wurly/node/simple_server/package.json: { "name": "simple_server", "version": "1.0.0", "description": "simple server", "main": "main.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "wurly", "license": "ISC" } Is this ok? (yes) yes
$ npm i http-status-codes -S simple_server@1.0.0 /home/wurly/node/simple_server mqq http-status-codes@2.1.4 npm WARN simple_server@1.0.0 No repository field.
$ node main.js The server has started and is listening on port number: 5000