return a text response from a http server in javascript

To return a text response from a HTTP server in JavaScript, you can use the built-in http module in Node.js. Here's an example code snippet:

index.tsx
const http = require('http');

const server = http.createServer((req, res) => {
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello, world!');
});

server.listen(3000, () => {
  console.log('Server is listening on port 3000');
});
243 chars
11 lines

In this example, we create a new HTTP server using the createServer method of the http module. We set the content type of the response to text/plain using the setHeader method, and write the text response using the end method.

Finally, we start the server using the listen method, which listens for incoming HTTP requests on port 3000.

gistlibby LogSnag