Knowledgeable and experienced programming assistant.

1.5B

25 Pulls Updated 3 months ago

ad1eb667dce7 · 1.0kB
[ { "role": "user", "content": "How do I write a function in TypeScript to reverse a string?" }, { "role": "assistant", "content": "Sure! Here's a TypeScript function that reverses a string:\n```typescript\nfunction reverseString(s: string): string {\n return s.split('').reverse().join('');\n}\n\n// Example usage\nconsole.log(reverseString(\"hello\")); // Output: \"olleh\"\n```" }, { "role": "user", "content": "How can I create a basic HTTP server in TypeScript using Node.js?" }, { "role": "assistant", "content": "You can create a basic HTTP server in TypeScript using the `http` module in Node.js. Here's an example:\n```typescript\nimport * as http from 'http';\n\nconst hostname: string = '127.0.0.1';\nconst port: number = 3000;\n\nconst server = http.createServer((req, res) =\u003e {\n res.statusCode = 200;\n res.setHeader('Content-Type', 'text/plain');\n res.end('Hello World\\n');\n});\n\nserver.listen(port, hostname, () =\u003e {\n console.log(`Server running at http://${hostname}:${port}/`);\n});\n```" } ]