NodeJS
Concept[edit]
Node.js ist eine plattformübergreifende Open-Source-JavaScript-Laufzeitumgebung, die JavaScript-Code außerhalb eines Webbrowsers ausführen kann.
node -v // prints version
Node.js has a set of built-in modules which you can use without any further installation, Consider modules to be the same as JavaScript libraries (see require or export).
npm[edit]
npm (ehemals Node Package Manager) ist ein Paketmanager für die JavaScript-Laufzeitumgebung Node.js. Unter dem Namen npm Registry bzw. npm Open Source wird ein Repository betrieben, über das 350.000 Pakete (Stand 13. Januar 2017[4]) unter einer freien Lizenz bereitgestellt werden. npm is the world's largest software registry. Open source developers from every continent use npm to share and borrow packages, and many organizations use npm to manage private development as well.
npm consists of three distinct components:
- the website
- the Command Line Interface (CLI)
- the registry
Use the website to discover packages, set up profiles, and manage other aspects of your npm experience. For example, you can set up organizations to manage access to public or private packages. The CLI runs from a terminal, and is how most developers interact with npm. The registry is a large public database of JavaScript software and the meta-information surrounding it.
npm -v // prints version
npm -g install %Modulname // -g installs to standard directory C:\Users\U1728\AppData\Roaming\npm\node_module, see npm -g list
// if -g is missing it will install it to current directory .\node_modules, see
npm list
npm -s // save option, adds the package to dependencies in package.json
package.json[edit]
package.json holds important information about a project. It contains human-readable metadata about the project (like the project name and description) as well as functional metadata like the package version number and a list of dependencies required by the application. It is used by the npm CLI (and yarn) to identify your project and understand how to handle the project's dependencies. It's the file that enables npm to start your project, run scripts, install dependencies, publish to the NPM registry, and many other useful tasks.
The scripts sections defines the commands which could be used by
npm run <SCRIPT>
e.g.
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "echo 'create build timestamp' && node ./src/environments/createBuildTimestamp.js && ng build",
"watch": "ng build --watch --configuration development",
"test": "ng test"
},
oddly enough some scripts can be called directly by npm <SCRIPT> but not the build script.
Examples[edit]
- see C:\Uwes\javascripts\test
Test1[edit]
- test1.js
var http = require('http'); // use module http
http.createServer(...).listen(8282)
node test1.js // creates a http server which listens to port 8282
http://localhost:8282 // netstat -a
Installation[edit]
The NPM program is installed on your computer when you install Node.js