gpt-3.5-turbo-0125· openai
from WildChat-4.8M
Write 10 random nodejs usefull codes
- User
Write 10 random nodejs usefull codes
- Assistant
- Read contents of a file synchronously:
javascriptconst fs = require('fs'); const data = fs.readFileSync('file.txt', 'utf8'); console.log(data);- Create a simple HTTP server:
javascriptconst http = require('http'); http.createServer((req, res) => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.end('Hello World'); }).listen(3000, 'localhost'); console.log('Server running at http://localhost:3000/');- Install a package using npm:
bashnpm install package-name- Use the 'path' module to manipulate file paths:
javascriptconst path = require('path'); const filePath = '/mydir/myfile.txt'; console.log(path.basename(filePath)); console.log(path.dirname(filePath));- Use 'process.argv' to access command line arguments:
javascriptconsole.log(process.argv);- Use 'setTimeout' to run a function after a specified delay:
javascriptsetTimeout(() => { console.log('Delayed function executed'); }, 2000);- Use 'crypto' module to generate MD5 hash of a string:
javascriptconst crypto = require('crypto'); const hash = crypto.createHash('md5').update('Hello').digest('hex'); console.log(hash);- Use 'dotenv' package to load environment variables from a .env file:
javascriptrequire('dotenv').config(); console.log(process.env.SECRET_KEY);
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.