Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b10a24a
feat: Add right rails work in progress
imbhargav5 Mar 15, 2019
9538231
feat: Add right rails on desktop
imbhargav5 Apr 4, 2019
8adb53a
fix: Prettier
imbhargav5 Apr 4, 2019
e259559
fix: Update styles as per review
imbhargav5 Apr 10, 2019
f849ca9
fix: Prettier formatting
imbhargav5 Apr 10, 2019
59ba33e
docs: add more info about environment
aymen94 Apr 24, 2019
879aaf2
remove duplicate line and add module dotenv
aymen94 Apr 27, 2019
afd36e5
change word
aymen94 Apr 28, 2019
fb229ad
remove word
BeniCheni Apr 30, 2019
0f90528
fix word
aymen94 Jun 9, 2019
c22fcf9
doc: add more ways
aymen94 Jun 10, 2019
2cce387
feat: Create placeholders for all top level pages
amiller-gh Sep 7, 2019
5917623
feat: Create placeholder /download page
amiller-gh Sep 7, 2019
a58b5c3
feat: Create hooks dir, add useReleaseHistory hook
jonchurch Sep 7, 2019
d29c04e
feat: Create custom hooks dir, create useReleaseData hook
jonchurch Sep 7, 2019
7d9d3c2
chore: Format useReleaseData with prettier
jonchurch Sep 7, 2019
6f7aa17
feat: Add API docs hook and render list of modules for POC API page
amiller-gh Sep 7, 2019
c11f4c5
newbs might get confused with readline var name being same as package…
ORESoftware Apr 21, 2020
2082227
Merge branch 'feat/right-rail' into sweep/den-3945-consolidate-all-br…
ORESoftware Sep 18, 2026
1769c5d
Merge branch 'aymen94-patch-1' into sweep/den-3945-consolidate-all-br…
ORESoftware Sep 18, 2026
deb2091
Merge branch 'api-docs' into sweep/den-3945-consolidate-all-branches-…
ORESoftware Sep 18, 2026
125940c
Merge branch 'patch-1' into sweep/den-3945-consolidate-all-branches-2…
ORESoftware Sep 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ exports.createPages = ({ graphql, actions }) => {

docPages.forEach(page => {
createPage({
path: `/${page.slug}`,
path: `/learn/${page.slug}`,
component: docTemplate,
context: {
slug: page.slug,
Expand All @@ -122,7 +122,7 @@ exports.createPages = ({ graphql, actions }) => {
});
if (page.slug === 'introduction-to-nodejs')
createPage({
path: `/`,
path: `/learn`,
component: docTemplate,
context: {
slug: page.slug,
Expand Down
11 changes: 5 additions & 6 deletions src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,13 @@ const Header = () => (
</Link>
</li>
<li className="nav__tabs">
<a target="_blank" href="https://nodejs.org/en/download/">
Download
</a>
<a href="/learn">Learn</a>
</li>
<li className="nav__tabs">
<a target="_blank" href="https://nodejs.org/en/docs/">
API Docs
</a>
<a href="/docs">Documentation</a>
</li>
<li className="nav__tabs">
<a href="/download">Download</a>
</li>
<li className="nav__tabs">
<a target="_blank" href="https://github.com/nodejs/nodejs.dev">
Expand Down
61 changes: 57 additions & 4 deletions src/components/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ code[class*="language-"] {

main {
display: grid;
grid-template-columns: 420px auto;
grid-template-columns: 420px auto 400px;
}

:focus {
Expand Down Expand Up @@ -169,7 +169,7 @@ main {
.hero {
align-items: center;
display: flex;
grid-column-end: 3;
grid-column-end: 4;
grid-column-start: 1;
height: var(--hero-height);
position: sticky;
Expand Down Expand Up @@ -401,9 +401,62 @@ main {
font-weight: 400;
line-height: 1.58;
letter-spacing: -.003em;
max-width: 768px;
padding-left: 4.2rem;
width: calc(100% - 36.0rem);
}

.toc-desktop{
display : hidden;
overflow: hidden;
position: sticky;
top: 140px;
width: 100%;
z-index: 998;
padding: 0 2.4rem;
height: calc(100vh - var(--nav-height));
}

.toc-desktop__nav{
position: sticky;
top : 0;
}
.toc-desktop__nav ul {
text-align: left;
list-style: none;
margin: 0;
padding: 0;
font-size: 1.2rem;
}

.toc-desktop__heading{
padding: 1.2rem;
font-weight: normal;
font-size: 1.4rem;
color: var(--gray7);
margin-bottom: 1rem;
}

.toc-desktop__nav a {
color: var(--gray9);
text-decoration: none;
display: block;
align-items: center;
border-radius: 4px;
box-sizing: border-box;
cursor: pointer;
line-height: 2.4rem;
list-style: none;
padding: 1.2rem;
position: relative;
width: calc(100% - 4.8rem);
}

@media(min-width:1263px){
.toc{
display : none;
}
.toc-desktop{
display : block;
}
}

/* sr-only for desktop */
Expand Down
19 changes: 19 additions & 0 deletions src/components/toc-desktop.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

type Props = {
heading: string;
tableOfContents: string;
};

function TOCDesktop({ heading, tableOfContents }: Props) {
return (
<div className="toc-desktop">
<nav className="toc-desktop__nav">
<h6 className="toc-desktop__heading">{heading}</h6>
<div dangerouslySetInnerHTML={{ __html: tableOfContents }} />
</nav>
</div>
);
}

export default TOCDesktop;
25 changes: 24 additions & 1 deletion src/documentation/0009-node-environment-variables/index.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
---
title: How to read environment variables from Node.js
description: 'Learn how to read and make use of environment variables in a Node.js program'
authors: flaviocopes, MylesBorins, fhemberger, LaRuaNa, ahmadawais
authors: flaviocopes, MylesBorins, fhemberger, LaRuaNa, ahmadawais, aymen94, Trott
section: Getting Started
---

The `process` core module of Node.js provides the `env` property which hosts all the environment variables that were set at the moment the process was started.

There are many ways to set environment variables, Here we cite some.

## We have some ways to set variables:
- using command line
- using a `.env` file
- Set environment variables in your shell and let node inherit them.
- Set the environment variable in `process.env.` Depending on your use case, that might be sufficient, or you might need to launch a subprocess to inherit it.
- In various contexts (such as launching a subprocess via child_process), you can set an env option.

### Using Command Line:

`PORT=8626 node app.js`

### Using a `.env` File:

We need to install [dotenv](https://www.npmjs.com/package/dotenv) module.

Create the .env file in the root of your app and add your variables and values to it.

```
NODE_ENV=development
PORT=8626
```
Here is an example that accesses the NODE_ENV environment variable, which is set to `development` by default.

> Note: `process` does not require a "require", it's automatically available.
Expand Down
4 changes: 2 additions & 2 deletions src/documentation/0014-node-input-from-cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ How to make a Node.js CLI program interactive?
Node.js since version 7 provides the [`readline` module](https://nodejs.org/api/readline.html) to perform exactly this: get input from a readable stream such as the `process.stdin` stream, which during the execution of a Node.js program is the terminal input, one line at a time.

```js
const readline = require('readline').createInterface({
const rl = require('readline').createInterface({
input: process.stdin,
output: process.stdout
})

readline.question(`What's your name?`, name => {
rl.question(`What's your name?`, name => {
console.log(`Hi ${name}!`)
readline.close()
})
Expand Down
2 changes: 2 additions & 0 deletions src/hooks/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { useApiData } from './useApiDocs';
export { useReleaseHistory } from './useReleaseHistory';
34 changes: 34 additions & 0 deletions src/hooks/useApiDocs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useState, useEffect } from 'react';

// TODO: Flesh out API types.
/* tslint:disable */
interface APIResponse {
classes: any[];
globals: any[];
methods: any[];
miscs: any[];
modules: any[];
}
/* tslint:enable */

export function useApiData(version: string): APIResponse {
const [apiData, setApiData] = useState<APIResponse>({
classes: [],
globals: [],
methods: [],
miscs: [],
modules: [],
});

useEffect(() => {
const fetchData = async () => {
const res = await window.fetch(
`https://nodejs.org/dist/${version}/docs/api/all.json`
);
setApiData((await res.json()) as APIResponse);
};
fetchData();
}, []);

return apiData;
}
15 changes: 15 additions & 0 deletions src/hooks/useReleaseHistory.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useState, useEffect } from 'react';

export function useReleaseHistory() {
const releasesURL = 'https://nodejs.org/dist/index.json';
const [releaseHistory, setReleaseHistory] = useState([]);
useEffect(() => {
const fetchData = async () => {
const result = await fetch(releasesURL).then(data => data.json());
setReleaseHistory(result);
};
fetchData();
}, []);

return releaseHistory;
}
26 changes: 26 additions & 0 deletions src/pages/docs.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react';
import { useApiData } from '../hooks';
import Hero from '../components/hero';
import Layout from '../components/layout';

export default () => {
const title = 'API Docs';
const description = 'Come learn yourself something.';
const apiData = useApiData('v12.9.1');

return (
<Layout title={title} description={description}>
<Hero title={title} />
<article style={{ width: '100%' }} className="article-reader">
<nav>
<ul>
{apiData.modules.map(module => (
<li key={module.name}>{module.displayName}</li>
))}
</ul>
</nav>
<p>Welcome to the API Page!</p>
</article>
</Layout>
);
};
17 changes: 17 additions & 0 deletions src/pages/download.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import Hero from '../components/hero';
import Layout from '../components/layout';

export default () => {
const title = 'Download Node.js';
const description = 'Come get me!';

return (
<Layout title={title} description={description}>
<Hero title={title} />
<article style={{ width: '100%' }} className="article-reader">
<p>Welcome to the Downloads Page!</p>
</article>
</Layout>
);
};
17 changes: 17 additions & 0 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import Hero from '../components/hero';
import Layout from '../components/layout';

export default () => {
const title = 'Home Page';
const description = 'Welcome to Node.js!';

return (
<Layout title={title} description={description}>
<Hero title={title} />
<article style={{ width: '100%' }} className="article-reader">
<p>Welcome to the Home Page!</p>
</article>
</Layout>
);
};
7 changes: 7 additions & 0 deletions src/templates/learn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Hero from '../components/hero';
import Layout from '../components/layout';
import Navigation from '../components/navigation';
import { LearnPageContext, LearnPageData } from '../types';
import TOCDesktop from '../components/toc-desktop';

type Props = {
data: LearnPageData;
Expand Down Expand Up @@ -35,6 +36,12 @@ export default ({
previous={previous}
relativePath={relativePath}
/>
{tableOfContents && (
<TOCDesktop
heading="TABLE OF CONTENTS"
tableOfContents={tableOfContents}
/>
)}
</Layout>
);
};
Expand Down