Yup, that clears it up!
There are a couple of different flavors of syntax for importing and exporting files in JavaScript, and which one you use depends on the environment you’re working in. You’re using web importing syntax instead of Node importing syntax (I’m pretty sure there are ways to work around this, but Node won’t interpret the web syntax by default)
For Node, the exporting syntax uses module.exports
, like so:
module.exports = url;
and the corresponding import syntax is:
const url = require('./Test');
If you wanted to export multiple things from the same file, it’s slightly different:
module.exports = {
url,
filePath
};
To import url
only:
const { url } = require('./Test');
To import both variables:
const { url, pathName } = require('./Test');
Codecademy has two articles from Learn Intermediate JavaScript that you may find helpful:
Implementing Modules in Node | Learn Intermediate JavaScript
Implementing Modules in ES6 | Learn Intermediate JavaScript
This is the official Node documentation on modules: Modules | Node Documentation
And this is the Node documentation on web module syntax – it looks like under the “Enabling” heading, there are some instructions on how to use this syntax in Node and make it work: ECMAScript Modules | Node Documentation
Whether you choose to convert to Node imports or configure your project to read the web imports is up to you, either should be valid!