gpt-3.5-turbo-0125· openai
from WildChat-4.8M
Write a 10 nodejs usefull code with your imagination
- User
Write a 10 nodejs usefull code with your imagination
- Assistant
- A code snippet to generate a random number between a specified range:
codeconst generateRandomNumber = (min, max) => { return Math.floor(Math.random() * (max - min + 1)) + min; } console.log(generateRandomNumber(1, 100)); // Output: Random number between 1 and 100- A code snippet to capitalize the first letter of a string:
codeconst capitalizeFirstLetter = (str) => { return str.charAt(0).toUpperCase() + str.slice(1); } console.log(capitalizeFirstLetter('hello world')); // Output: Hello world- A code snippet to fetch data from an API using axios:
codeconst axios = require('axios'); axios.get('https://jsonplaceholder.typicode.com/posts') .then(response => { console.log(response.data); }) .catch(error => { console.error(error); });- A code snippet to write data to a file using fs module:
codeconst fs = require('fs'); const data = 'Hello, world!'; fs.writeFile('output.txt', data, (err) => { if (err) throw err; console.log('Data written to file'); });- A code snippet to read data from a file using fs module:
codeconst fs = require('fs'); fs.readFile('input.txt', 'utf8', (err, data) => { if (err) throw err; console.log(data); });- A code snippet to create a simple HTTP server using Express:
codeconst express = require('express'); const app = express(); app.get('/', (req, res) => { res.send('Hello, world!'); }); app.listen(3000, () => { console.log('Server running on port 3000'); });
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.