import

I am building an app in HTTPS-NODE, and when I try to import something from my js file, it cannot find it, event if I put "import path from '/node_modules/path' it just doesn't find anything... Can someone help me?
24 Replies
Percy
Percy2y ago
Project ID: N/A
KChammas
KChammasOP2y ago
N/A
Percy
Percy2y ago
If it is just a regular json file, you can just import and then return it.
⚠️ experimental feature
KChammas
KChammasOP2y ago
Does not works
Brody
Brody2y ago
could we see a repo?
KChammas
KChammasOP2y ago
Can I just write it down over here? That's my server.mjs (main file) import express from 'express'; var app = express(); import path, { join } from 'path'; import { createServer } from 'http'; import { fileURLToPath } from 'url'; const filename = fileURLToPath(import.meta.url); const dirname = path.dirname(filename); var server = createServer(app); server.listen(process.env.PORT); app.use(express.static(join(dirname, 'public'))); app.use('/src',express.static(join(dirname, 'public/src'))); app.use('/node_modules',express.static(join(dirname, 'node_modules'))); app.use('/html',express.static(join(dirname, 'public/html'))); app.get('/', function (req, res) { res.sendFile(dirname + '/index.html'); }); And this is how I'm trying to import on my teste.mjs (file for the page): import path from '/node_modules/path'; import { fileURLToPath } from '/node_modules/url';
KChammas
KChammasOP2y ago
That's the structure
Brody
Brody2y ago
id prefer a repo
KChammas
KChammasOP2y ago
The repo, is it the repository on github? I'm new at git therms
Brody
Brody2y ago
yes i dont know if repo is a term, im just lazy
KChammas
KChammasOP2y ago
GitHub
GitHub - kevinuzan/http-nodejs
Contribute to kevinuzan/http-nodejs development by creating an account on GitHub.
KChammas
KChammasOP2y ago
There u go
Brody
Brody2y ago
okay now can i see a screenshot of the deploy log error
KChammas
KChammasOP2y ago
KChammas
KChammasOP2y ago
I just don't know how to import a module to my teste.mjs...
Brody
Brody2y ago
so why do you need to access the node_modules folder in the frontend?
KChammas
KChammasOP2y ago
I mean, I need to import the module on a mjs file That one that you are seeing on the html, was just a test
Brody
Brody2y ago
thats not quite how that works
KChammas
KChammasOP2y ago
Here is what I want it to do: When I click on a button, it loads a new html, changing the screen But to do it, shouldn't I kind of tell it where is the file and all?
Brody
Brody2y ago
no you shouldn't need to access the node_modules folder in the frontend, i recommend you look for some tutorials on this topic and work through them locally
KChammas
KChammasOP2y ago
So if I need to use a module, like for example, postgreSQL module, on my webapp, shouldn't I import it on my mjs file?
Brody
Brody2y ago
i guess im just struggling to explain this, normally you would use a bundler like vite
KChammas
KChammasOP2y ago
And that's what makes the "Connection" between the modules that I installed on my app, and my pages?
Brody
Brody2y ago
vite will bundle your code and any required module into the same file
Want results from more Discord servers?
Add your server