-
Couldn't load subscription status.
- Fork 333
updating the node page to simplify #2685
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! A quick start section is nice
| ### Import an npm package | ||
|
|
||
| ```ts title="main.ts" | ||
| import chalk from "npm:chalk@5"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly feel we should limit number of examples using npm: specifiers in the docs website and should prefer deno install npm:chalk and then import chalk from "chalk"; so it's as familiar as possible to people coming from Node
| // CommonJS works out of the box | ||
| module.exports = { ok: true }; | ||
| console.log("CJS runs in Deno"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // CommonJS works out of the box | |
| module.exports = { ok: true }; | |
| console.log("CJS runs in Deno"); | |
| const chalk = require("chalk"); | |
| console.log(chalk.green("Hello from npm in Deno")); |
| deno run main.ts | ||
| ``` | ||
|
|
||
| ### Run a .cjs file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ### Run a .cjs file | |
| ### Execute CommonJS |
|
|
||
| ### Run a .cjs file | ||
|
|
||
| ```js title="main.cjs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```js title="main.cjs" | |
| Use `.cjs` extension to inform Deno that module is using CommonJS system. | |
| ```js title="main.cjs" |
| ```js title="process.mjs" | ||
| import process from "node:process"; | ||
| console.log(process.platform); | ||
| ``` | ||
|
|
||
| ```sh | ||
| deno run process.mjs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ```js title="process.mjs" | |
| import process from "node:process"; | |
| console.log(process.platform); | |
| ``` | |
| ```sh | |
| deno run process.mjs | |
| ```js title="process.js" | |
| import path from "node:path"; | |
| console.log(path.join("./foo", "../bar")); |
deno run process.js(.mjs is not important and process is widely available as a global)
| using `nodeModulesDir` in `deno.json` or the `--node-modules-dir` flag (see the | ||
| node_modules section below). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| using `nodeModulesDir` in `deno.json` or the `--node-modules-dir` flag (see the | |
| node_modules section below). | |
| using `nodeModulesDir` in `deno.json`. |
Updating as per @littledivy's feedback in #2684
Added: Quick start
Added: First-class package.json support
Reordered: Node.js global objects earlier
Simplified: CommonJS intro and troubleshooting
Added: .cjs run example (deno run -A main.cjs)
Added: node_modules mode decision guide
Removed: npx analogy snippet
Renamed: Deno 1.X-specific node_modules subsection
Compressed: Migrating and Optional improvements
Content refocused on tasks and outcomes
Duplicates removed and legacy bits trimmed
Headings and structure tightened
@littledivy please feel free to edit/remove details as you see fit!