nodejs css cotent tipe
To set the content type for a CSS file in Node.js, you can follow the steps below:
- First, import the
http
module, which provides functionality to create an HTTP server in Node.js:
const http = require('http');
- Create a server using the
createServer
method of thehttp
module:
const server = http.createServer((req, res) => {
// Server logic goes here
});
- Inside the server logic, use the
writeHead
method of theresponse
object to set the content type header to "text/css":
res.writeHead(200, { 'Content-Type': 'text/css' });
- Finally, use the
end
method of theresponse
object to send the response back to the client:
res.end('CSS content goes here');
Here is the complete code snippet for setting the content type for a CSS file in Node.js:
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/css' });
res.end('CSS content goes here');
});
server.listen(3000, () => {
console.log('Server is running on port 3000');
});
Please note that you need to replace 'CSS content goes here'
with the actual content of your CSS file.