Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 1583
Alex Hales
  • 0
Alex HalesTeacher
Asked: May 30, 20222022-05-30T20:41:22+00:00 2022-05-30T20:41:22+00:00

javascript – How do I send multiple files when the server is requested using node.js?

  • 0

[ad_1]

I’m new to anything web-development related (I’ve only been coding using luau for about a year now), and I’m having trouble sending multiple files when my server gets pinged, because I want to have a separate style.css file, as well as different script things.

I’ve left out MouseDraw.js and style.css, but when I added them directly into index.html they worked, and I can’t see them when I inspect element on the website so I think it’s just that they aren’t being sent.

Is it possible to send them or do I have to just put them in every file?

I would post an image of how it’s structured but I’m new so I can’t, but it’s all under a folder, and then there’s just ‘Server.js’ and a folder called Client, which has everything I want to send to the client.

Server code:

const http = require('http');

const fs = require('fs').promises

const hostname="localhost";
const port = 8000;

let loadedPageInfo;

fs.readFile(__dirname + "/Client/index.html")  // Get and read the HTML data for this page
    .then((contents) => {
        loadedPageInfo = contents
    })
    .catch((error) => {
        console.log(`Could not load index.html ${error}`)
    })

const server = http.createServer((req, res) => {
    res.end(loadedPageInfo || "Error loading");
});

server.listen(port, hostname, () => {
    console.log(`Server running at http://${hostname}:${port}/`);
});

Client:

index.html:


<head>
    <title>Drawing</title>
    <link rel = "stylsheet" type = "text/css" href = "style.css">

</head>

<body> 
    <h1>Heading One</h1>
    <p1>Message from my computer:</p1>

    <p2><samp><br><br>File not found.<br>Press F1 to do nothing</samp></p2>

</body>

<script> src = "MouseDraw.js" </script>

</html>

[ad_2]

  • 0 0 Answers
  • 14 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 4993 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1084 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1028 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.