Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 396 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can you import node's path module using import path from 'path'

#1
I prefer using the `import x from 'y'` syntax, but all I've seen online is `const path = require('path')`.

Is there a way to import the path module using this syntax?
Reply

#2
You can either do

`import module from 'path'`

or if you just need to import `path` just do

`import 'path'`
Reply

#3
If the version of nodejs you're using supports the ES 6 features, then yes. Otherwise not. Most of the older versions (pre 6.x if memory serves but you should check for your version) required the --harmony flag in order to do this, the latest releases include it natively.

For this reason, and because it works in all versions, most online resources still use the require syntax.
Reply

#4
**For people trying to import `path` in a TypeScript file, and ending up here:**

1. Be sure to have node types installed:

npm install --save-dev @types/node

2. Import path symbol:

import * as path from 'path';


Note: `@types/*` are automatically included for compilation, providing you use typescript version 2.0 or above, and provided you don't override the `types` property in compiler options file (*tsconfig.json*).

Reply

#5
If not using typescript

import * as path from 'path'

is the only thing that works for me.




Reply

#6
import path from 'path';

As of now, this is the code that's working for me in typescript.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through