fixes to nodejs compat

This commit is contained in:
Vivek Singh
2024-10-15 11:03:37 +05:30
parent 41c183df0a
commit 2335c089ed

View File

@@ -88,7 +88,8 @@ To get the full Node.js compatible layer that Bare currently supports add the fo
``` ```
## Consuming dependencies that use core Node.js modules ## Consuming dependencies that use core Node.js modules
If your project depends on a module that uses a core [Node.js](https://nodejs.org/en/download) module, use [NPM aliases](./nodejs-compatibility-with-bare.md#consuming-dependencies-using-npm-aliases) or [import maps](./nodejs-compatibility-with-bare.md#consuming-dependencies-using-import-maps) to consume the Bare version of the module. If the project dependencies use core [Node.js](https://nodejs.org/en/download) modules, use [NPM aliases](./nodejs-compatibility-with-bare.md#consuming-dependencies-using-npm-aliases) or [import maps](./nodejs-compatibility-with-bare.md#consuming-dependencies-using-import-maps) to consume the Bare version of those modules.
@@ -120,7 +121,7 @@ const myPackage = require('my-package');
### Example of using `fs` in a project using aliases ### Example of using `fs` in a project using aliases
> Make sure [Node.js](https://nodejs.org/en/download) is installed on your system. This can be checked by running `node -v` in your terminal. > Make sure [Node.js](https://nodejs.org/en/download) is installed on your system. This can be checked by running `node -v` in the terminal.
#### Start a new project #### Start a new project
@@ -132,9 +133,7 @@ cd test-fs
pear init --yes --type=terminal pear init --yes --type=terminal
``` ```
Replace the contents of `index.js` with the following. Replace the contents of `index.js` with the following:
This will create a file called `test.txt` and write a string to it. It will then read the file and log the content to the console.
```js ```js
import * as fs from 'node:fs'; import * as fs from 'node:fs';
@@ -154,6 +153,9 @@ async function test() {
test(); test();
``` ```
This will create a file called `test.txt` and write a string to it. It will then read the file and log the content to the console.
Now run the file using Node.js. Now run the file using Node.js.
```bash ```bash