Commit c60c76cf authored by Caleb C. Sander's avatar Caleb C. Sander
Browse files

Remove notes about npm

parent 573c4525
No related merge requests found
Showing with 0 additions and 39 deletions
+0 -39
......@@ -30,7 +30,6 @@
- [Running programs in Node.js](#running-the-interpreter)
- [Modules](#modules): Node.js builtin modules, `require`, and `module.exports`
- [Example](#nodejs-example)
- [npm](#installing-npm-packages): using open-source libraries with npm
- [Documentation](#nodejs-documentation)
---
......@@ -907,7 +906,6 @@ list234.toArray() // [2, 3, 4]
Most of the functions included in Node.js need to be imported from the corresponding library, e.g. `fs` for file system operations, `http` for making HTTP servers and requests, and `zlib` for compressing and decompressing files.
See the example below for using one of these modules.
[npm packages](#installing-npm-packages) are also imported the same way.
### Node.js example
......@@ -940,43 +938,6 @@ fs.readFile(source, (err, data) => {
})
```
### Installing npm packages
If you haven't used a package manager before, the idea is simple: they allow people to publish open source code libraries for other projects to use.
Node.js's package manager is called [npm](npmjs.com) and it hosts more published packages than any other package manager.
If you want to use npm with a new project, run `npm init` to create a `package.json` file: this file stores information about the project, including which packages it depends on.
However, we will provide you all the `package.json` files you need.
To install the "dependencies" specified in `package.json`, run `npm install`.
For example, the [`colors`](https://www.npmjs.com/package/colors) package on npm allows you to print colored text in the terminal.
You could use the following `package.json` for a new project `colors-test` that depends on version 1.4.0 or newer of `colors`:
```json
{
"name": "colors-test",
"version": "0.0.1",
"dependencies": {
"colors": "^1.4.0"
}
}
```
Running `npm install` installs `colors` and prints:
```
added 1 package from 2 contributors and audited 1 package in 0.323s
found 0 vulnerabilities
```
Now we can `require('colors')` in our program:
```js
const colors = require('colors')
console.log(
colors.red('r') +
colors.yellow('y') +
colors.green('g') +
colors.blue('b')
)
```
Running this program prints:
![Colors test](colors.png)
### Node.js documentation
Node.js also has very detailed documentation of its standard library at [nodejs.org](https://nodejs.org/api/).
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment