0

I am using expressJS in my nodeJS application. I am getting the following error while rendering (using sendFile) an html file containing js code src="../../viewer/something.js" to a browser from a route requested from a browser client:

The resource from “http://localhost:3000/viewer/something.js” was blocked due to MIME type (“text/html”) mismatch (X-Content-Type-Options: nosniff). Loading failed for the with source “http://localhost:3000/viewer/something.js”.

I even tried to define the Content-Type=“text/javascript” in the above line of the HTML page. How do I enable inclusion of the src file in the HTML files rendered from nodejs using sendFile? Can someone help please?

2
  • I guess this is to do with the file path not resolving more than the content type issue. Check if you can hit the JS file url from browser and that it can load Commented Mar 17, 2020 at 4:24
  • yes as mentioned below. Commented Mar 17, 2020 at 7:38

1 Answer 1

1

You should set your static folder like this

app.use(express.static(__dirname + '/public'));

Also, You'll need to give your HTML file the right path to your script file.

<script src="/viewer/something.js"></script>

Sign up to request clarification or add additional context in comments.

2 Comments

I think that was it! Thanks a lot Vaibhav!
@prafull Thank you for replying. I'm glad your issue was resolved. Thank you, too.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.