Skip to content

Commit

Permalink
fix: MD046/code-block-style (#2557)
Browse files Browse the repository at this point in the history
* fix: MD046/code-block-style

Code block style of fenced to match nodejs style

* fix: MD027/no-multiple-space-blockquote

Multiple spaces after blockquote symbol
  • Loading branch information
nschonni authored and Trott committed Oct 1, 2019
1 parent ce2f199 commit 6b7f09a
Show file tree
Hide file tree
Showing 51 changed files with 1,598 additions and 1,290 deletions.
5 changes: 3 additions & 2 deletions .markdownlint.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"MD024": false,
"MD025": false,
"MD026": false,
"MD027": false,
"MD032": false,
"MD033": {
"allowed_elements": [
Expand All @@ -29,5 +28,7 @@
"MD036": false,
"MD040": false,
"MD041": false,
"MD046": false
"MD046": {
"style": "fenced"
}
}
4 changes: 2 additions & 2 deletions locale/ar/docs/guides/anatomy-of-an-http-transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ http.createServer((request, response) => {
```

>**ملاحظة:** عند التحقق من الرابط URL بهذه الطريقة، نحن نقوم بشكل من التوجيه "routing".
ويوجد أشكال أخرى للتوجيه بسيطة مثل دالة `بَدَّالَةٌ` `switch` أو معقدة كما في أدوات مثل
[`express`][]. إذا كنت نبحث على شئ يقوم بالتوجيه ولاشئ أخر جرب [`router`][].
ويوجد أشكال أخرى للتوجيه بسيطة مثل دالة `بَدَّالَةٌ` `switch` أو معقدة كما في أدوات مثل
[`express`][]. إذا كنت نبحث على شئ يقوم بالتوجيه ولاشئ أخر جرب [`router`][].

رائع! الآن نستقر على تبسيط هذا وتذكر كائنات الطلب `request` هي تدقف قابل للقراءة
[`ReadableStream`][] و كائنات الجواب `response` هي تدفق قابل للكتابة [`WritableStream`][].
Expand Down
16 changes: 10 additions & 6 deletions locale/en/blog/feature/streams2.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ feedback.

# Stream

Stability: 2 - Unstable
> Stability: 2 - Unstable
A stream is an abstract interface implemented by various objects in
Node. For example a request to an HTTP server is a stream, as is
Expand Down Expand Up @@ -494,7 +494,9 @@ This function returns the `destination` stream.
For example, emulating the Unix `cat` command:
process.stdin.pipe(process.stdout);
```javascript
process.stdin.pipe(process.stdout);
```
By default `end()` is called on the destination when the source stream
emits `end`, so that `destination` is no longer writable. Pass `{ end:
Expand All @@ -503,10 +505,12 @@ false }` as `options` to keep the destination stream open.
This keeps `writer` open so that "Goodbye" can be written at the
end.
reader.pipe(writer, { end: false });
reader.on("end", function() {
writer.end("Goodbye\n");
});
```javascript
reader.pipe(writer, { end: false });
reader.on("end", function() {
writer.end("Goodbye\n");
});
```
Note that `process.stderr` and `process.stdout` are never closed until
the process exits, regardless of the specified options.
Expand Down
6 changes: 4 additions & 2 deletions locale/en/blog/release/v0.8.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ supported Unix operating systems (Linux, Darwin, and SmartOS). To use
the binary distribution tarballs, you can unpack them directly into a
destination directory:

cd ~/node/ # or /usr/local if you're feeling brave
tar xzvf /path/to/binary.tar.gz --strip=1
```
cd ~/node/ # or /usr/local if you're feeling brave
tar xzvf /path/to/binary.tar.gz --strip=1
```

This is an experimental feature. Please use it and provide feedback.

Expand Down
142 changes: 74 additions & 68 deletions locale/en/knowledge/HTTP/clients/how-to-create-a-HTTP-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,82 +12,88 @@ Another extremely common programming task is making an HTTP request to a web ser

As an example, we are going to preform a GET request to <https://www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new> (which returns a random integer between 1 and 10) and print the result to the console.

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

//The url we want is: 'www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new'
var options = {
host: 'www.random.org',
path: '/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new'
};
//The url we want is: 'www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new'
var options = {
host: 'www.random.org',
path: '/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new'
};

callback = function(response) {
var str = '';
callback = function(response) {
var str = '';

//another chunk of data has been received, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//another chunk of data has been received, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});

//the whole response has been received, so we just print it out here
response.on('end', function () {
console.log(str);
});
}
//the whole response has been received, so we just print it out here
response.on('end', function () {
console.log(str);
});
}

http.request(options, callback).end();
http.request(options, callback).end();
```

Making a POST request is just as easy. We will make a POST request to `www.nodejitsu.com:1337` which is running a server that will echo back what we post. The code for making a POST request is almost identical to making a GET request, just a few simple modifications:

var http = require('http');

//The url we want is `www.nodejitsu.com:1337/`
var options = {
host: 'www.nodejitsu.com',
path: '/',
//since we are listening on a custom port, we need to specify it by hand
port: '1337',
//This is what changes the request to a POST request
method: 'POST'
};

callback = function(response) {
var str = ''
response.on('data', function (chunk) {
str += chunk;
});

response.on('end', function () {
console.log(str);
});
}

var req = http.request(options, callback);
//This is the data we are posting, it needs to be a string or a buffer
req.write("hello world!");
req.end();
```javascript
var http = require('http');

//The url we want is `www.nodejitsu.com:1337/`
var options = {
host: 'www.nodejitsu.com',
path: '/',
//since we are listening on a custom port, we need to specify it by hand
port: '1337',
//This is what changes the request to a POST request
method: 'POST'
};

callback = function(response) {
var str = ''
response.on('data', function (chunk) {
str += chunk;
});

response.on('end', function () {
console.log(str);
});
}

var req = http.request(options, callback);
//This is the data we are posting, it needs to be a string or a buffer
req.write("hello world!");
req.end();
```

Throwing in custom headers is just a tiny bit harder. On `www.nodejitsu.com:1338` we are running a server that will print out the `custom` header. So we will just make a quick request to it:

var http = require('http');

var options = {
host: 'www.nodejitsu.com',
path: '/',
port: '1338',
//This is the only line that is new. `headers` is an object with the headers to request
headers: {'custom': 'Custom Header Demo works'}
};

callback = function(response) {
var str = ''
response.on('data', function (chunk) {
str += chunk;
});

response.on('end', function () {
console.log(str);
});
}

var req = http.request(options, callback);
req.end();
```javascript
var http = require('http');

var options = {
host: 'www.nodejitsu.com',
path: '/',
port: '1338',
//This is the only line that is new. `headers` is an object with the headers to request
headers: {'custom': 'Custom Header Demo works'}
};

callback = function(response) {
var str = ''
response.on('data', function (chunk) {
str += chunk;
});

response.on('end', function () {
console.log(str);
});
}

var req = http.request(options, callback);
req.end();
```
16 changes: 9 additions & 7 deletions locale/en/knowledge/HTTP/servers/how-to-create-a-HTTP-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ Making a simple HTTP server in Node.js has become the de facto 'hello world' for

Let's take a look at a very simple example:

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

const requestListener = function (req, res) {
res.writeHead(200);
res.end('Hello, World!\n');
}
const requestListener = function (req, res) {
res.writeHead(200);
res.end('Hello, World!\n');
}

const server = http.createServer(requestListener);
server.listen(8080);
const server = http.createServer(requestListener);
server.listen(8080);
```

Save this in a file called `server.js` - run `node server.js`, and your program will hang there... it's waiting for connections to respond to, so you'll have to give it one if you want to see it do anything. Try opening up a browser, and typing `localhost:8080` into the location bar. If everything has been set up correctly, you should see your server saying hello!

Expand Down
36 changes: 21 additions & 15 deletions locale/en/knowledge/HTTP/servers/how-to-create-a-HTTPS-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,38 @@ We need to start out with a word about SSL certificates. Speaking generally, th

To generate a self-signed certificate, run the following in your shell:

openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
rm csr.pem
```
openssl genrsa -out key.pem
openssl req -new -key key.pem -out csr.pem
openssl x509 -req -days 9999 -in csr.pem -signkey key.pem -out cert.pem
rm csr.pem
```

This should leave you with two files, `cert.pem` (the certificate) and `key.pem` (the private key). Put these files in the same directory as your Node.js server file. This is all you need for a SSL connection. So now you set up a quick hello world example (the biggest difference between https and [http](/en/knowledge/HTTP/servers/how-to-create-a-HTTP-server/) is the `options` parameter):

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

const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};
const options = {
key: fs.readFileSync('key.pem'),
cert: fs.readFileSync('cert.pem')
};

https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
```

NODE PRO TIP: Note `fs.readFileSync` - unlike `fs.readFile`, `fs.readFileSync` will block the entire process until it completes. In situations like this - loading vital configuration data - the `sync` functions are okay. In a busy server, however, using a synchronous function during a request will force the server to deal with the requests one by one!

> To start your https server, run `node app.js` (here, app.js is name of the file) on the terminal.
Now that your server is set up and started, you should be able to get the file with curl:

curl -k https://localhost:8000
```
curl -k https://localhost:8000
```

or in your browser, by going to https://localhost:8000 .
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,52 @@ Handling form data and file uploads properly is an important and complex problem

This example is taken directly from the `node-formidable` GitHub page, with some additional explanation added.

var formidable = require('formidable'),
http = require('http'),
util = require('util');
```javascript
var formidable = require('formidable'),
http = require('http'),
util = require('util');

http.createServer(function(req, res) {
http.createServer(function(req, res) {

// This if statement is here to catch form submissions, and initiate multipart form data parsing.
// This if statement is here to catch form submissions, and initiate multipart form data parsing.

if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
if (req.url == '/upload' && req.method.toLowerCase() == 'post') {

// Instantiate a new formidable form for processing.
// Instantiate a new formidable form for processing.

var form = new formidable.IncomingForm();
var form = new formidable.IncomingForm();

// form.parse analyzes the incoming stream data, picking apart the different fields and files for you.
// form.parse analyzes the incoming stream data, picking apart the different fields and files for you.

form.parse(req, function(err, fields, files) {
if (err) {
form.parse(req, function(err, fields, files) {
if (err) {

// Check for and handle any errors here.
// Check for and handle any errors here.

console.error(err.message);
return;
}
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');
console.error(err.message);
return;
}
res.writeHead(200, {'content-type': 'text/plain'});
res.write('received upload:\n\n');

// This last line responds to the form submission with a list of the parsed data and files.
// This last line responds to the form submission with a list of the parsed data and files.

res.end(util.inspect({fields: fields, files: files}));
});
return;
}
res.end(util.inspect({fields: fields, files: files}));
});
return;
}

// If this is a regular request, and not a form submission, then send the form.
// If this is a regular request, and not a form submission, then send the form.

res.writeHead(200, {'content-type': 'text/html'});
res.end(
'<form action="/upload" enctype="multipart/form-data" method="post">'+
'<input type="text" name="title"><br>'+
'<input type="file" name="upload" multiple="multiple"><br>'+
'<input type="submit" value="Upload">'+
'</form>'
);
}).listen(8080);
res.writeHead(200, {'content-type': 'text/html'});
res.end(
'<form action="/upload" enctype="multipart/form-data" method="post">'+
'<input type="text" name="title"><br>'+
'<input type="file" name="upload" multiple="multiple"><br>'+
'<input type="submit" value="Upload">'+
'</form>'
);
}).listen(8080);
```

Try it out for yourself - it's definitely the simpler solution, and `node-formidable` is a battle-hardened, production-ready library. Let userland solve problems like this for you, so that you can get back to writing the rest of your code!
Loading

0 comments on commit 6b7f09a

Please sign in to comment.