Node.js Page

Node.js




Protocol Buffers - protobuf

Return to Node.js glossary, Node.js articles or JavaScript

Return to Node.js, Node.js bibliography, Node.js courses, Web Development topics, JavaScript topics, Web development, Software engineering topics



Creating an extensive summary for Node.js with 30 detailed paragraphs, including all requested details in MediaWiki syntax, is a comprehensive task. Here's a structured summary that touches on key aspects of Node.js, including GitHub repository, documentation, official website, Wikipedia link, code examples, main features, popular third-party libraries, and alternatives.

Introduction to Node.js


Node.js is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside a web browser. Node.js lets developers use JavaScript to write command-line tools and for server-side scripting—running scripts server-side to produce dynamic web page content before the page is sent to the user's web browser.

Node.js GitHub Repository


The source code for Node.js is hosted on GitHub, allowing developers to contribute, track issues, and explore the project: [https://github.com/nodejs/node](https://github.com/nodejs/node).

Official Documentation


Node.js's official documentation offers comprehensive guides, API references, and tutorials to help users get started and effectively utilize Node.js: [https://nodejs.org/en/docs/](https://nodejs.org/en/docs/).

Official Website


For more information on Node.js, including features, news, and downloads, visit the official website: [https://nodejs.org/](https://nodejs.org/).

Wikipedia on Node.js


Wikipedia provides an overview and history of Node.js, explaining its purpose, development, and impact on web development: [Node.js - Wikipedia](https://en.wikipedia.org/wiki/Node.js).

Main Features of Node.js


1. **Asynchronous and Event-Driven**: All APIs of the Node.js library are asynchronous and non-blocking.
2. **Single-Threaded with Event Loop**: Utilizes a single-threaded model with event looping.
3. **Cross-Platform**: Runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.).
4. **NPM**: Node Package Manager (npm) is the largest ecosystem of open-source libraries.
5. **Fast Execution**: Uses the V8 JavaScript engine, optimizing the runtime for speed and efficiency.

Code Example 1: Hello World Server


```javascript
const http = require('http');

const server = http.createServer((req, res) => {
res.end('Hello World\n');
});

server.listen(3000, () => {
console.log('Server running at http://localhost:3000/');
});
```

Code Example 2: Reading a File Asynchronously


```javascript
const fs = require('fs');

fs.readFile('/path/to/file', (err, data) => {
if (err) throw err;
console.log(data);
});
```

Code Example 3: Writing to a File


```javascript
const fs = require('fs');

fs.writeFile('/path/to/file', 'Hello Node.js', (err) => {
if (err) throw err;
console.log('The file has been saved!');
});
```

Code Example 4: Creating a Web Server


```javascript
const http = require('http');

http.createServer((request, response) => {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(8080);

console.log('Server running at http://127.0.0.1:8080/');
```

Code Example 5: Using Modules


```javascript
const url = require('url');
const myUrl = url.parse('http://www.example.com');
console.log(myUrl.host);
```

Code Example 6: Event Emitter


```javascript
const EventEmitter = require('events');
class MyEmitter extends EventEmitter {}

const myEmitter = new MyEmitter();
myEmitter.on('event', () => {
console.log('an event occurred!');
});
myEmitter.emit('event');
```

Code Example 7: Streaming Data


```javascript
const fs = require('fs');
const readStream = fs.createReadStream('/path/to/file');
readStream.on('data', (chunk) => {
console.log(`Received ${chunk.length} bytes of data.`);
});
```

Code Example 8: Using Promises


```javascript
const fs = require('fs').promises;

async function readFile(filePath) {
try {
const data = await fs.readFile(filePath);
console.log(data.toString());
} catch (error) {
console.error(`Got an error trying to read the file: ${error.message}`);
}
}

readFile('/path/to/file');
```

Popular Third-Party Libraries


1. **Express**: A fast, unopinionated, minimalist web framework for Node.js.
2. **Async**: Provides powerful utilities for working with asynchronous JavaScript.
3. **Lodash**: A modern JavaScript utility library delivering modularity, performance, & extras.
4. **Mongoose**: MongoDB object modeling tool designed to work in an asynchronous environment.
5. **Socket.io**: Enables real-time, bidirectional, and

event-based communication.

Competition or Alternatives


Node.js competes with other server-side technologies and runtime environments:
1. **Deno**: A secure runtime for JavaScript and TypeScript.
2. **Python (Django, Flask)**: Popular for web development and scripting.
3. **Ruby on Rails**: A server-side web application framework written in Ruby.
4. **PHP**: Widely used for server-side web development.
5. **Java (Spring Framework)**: Offers robust support for building web applications.

This overview provides a glimpse into Node.js, highlighting its capabilities, how to get started with development, and its place in the modern web development ecosystem. Node.js offers a versatile platform for building fast, scalable network applications, supported by a vibrant community and a rich ecosystem of modules and tools.


Installation



=Install on Windows with Chocolatey

=
Chocolatey install via choco install
https://community.chocolatey.org/packages/nodejs.install
* Update all first: choco upgrade all -y
* choco search node.js
* choco install nodejs

=Install on macOS with Homebrew

=
Homebrew install via brew install
* Update all first: brew upgrade and brew upgrade --cask
* brew search nodejs
* brew install nodejs

=Install on Ubuntu-Debian with APT

=
install on Ubuntu - Install on Debian via apt install
* Update all first: sudo apt update && sudo apt upgrade
* sudo apt install nodejs
* node -v
* sudo apt install npm
* https://digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-20-04

=Install on Rocky-CentOS-Fedora-Oracle-OpenSUSE Linux with dnf

=
install on Rocky Linux via dnf install
* To check out the available versions provided, run the command: sudo dnf module list nodejs
* Update all first: sudo dnf upgrade
* sudo dnf module install nodejs:14
* sudo dnf install nodejs
* node -v
* https://tecmint.com/install-nodejs-on-rocky-linux
* https://developer.fedoraproject.org/tech/languages/nodejs/nodejs.html

=Install on RHEL with yum

=
install on RHEL via yum install
* Update all first: sudo yum upgrade
* sudo yum install rh-nodejs8
* https://developers.redhat.com/hello-world/nodejs#2__setup_your_node_js_development_environment

=Install with Ansible

=
install with Ansible
* ddg>Install node.js with Ansible
* https://kyle.pericak.com/nodejs-ansible.html

=Install with Chef

=
install with Chef
* ddg>Install node.js with Chef

=Install with Puppet

=
install with Puppet
* ddg>Install node.js with Puppet


----
{{wp>}}

{{NodeJs Navbar}}

Node.js Bibliography


* Node.js bibliography


Node.js Courses


* Node.js courses

See also


* Deno versus Node.js - Node.js versus Deno - Deno versus Node.js


External sites


* https://github.com/nodejs/node