Hacker News new | ask | show | jobs
by spaceman_2020 1287 days ago
I've been using it for small blocks of code or specific functions - stuff I'd have to look up documentation or Stackoverflow for. I see it as a productivity booster, not a replacement.

You can't tell it to "create a CRUD app", but you can ask it to create a nodejs function that gets all the records from a mongodb database.

2 comments

You can ask for a simple example of a CRUD app, here's my code output:

const express = require('express')

const app = express()

// define the model for a user

const User = {

  name: '',

  email: ''
}

// create a new user

app.post('/users', (req, res) => {

  const user = Object.assign({}, User, req.body)


  // save the user to a database, etc.


  res.send(user)

})

// read a list of users

app.get('/users', (req, res) => {

  // retrieve a list of users from the database, etc.

  res.send([

    { name: 'Alice', email: 'alice@example.com' },

    { name: 'Bob', email: 'bob@example.com' }

  ])
})

// read a single user

app.get('/users/:id', (req, res) => {

  // retrieve a user with the specified id from the database, etc.

  res.send({ name: 'Alice', email: 'alice@example.com' })
})

// update a user

app.put('/users/:id', (req, res) => {

  // retrieve the user with the specified id from the 
database, etc. const user = Object.assign({}, User, req.body)

  // save the updated user to the database, etc.

  res.send(user)
})

// delete a user

app.delete('/users/:id', (req, res) => {

  // delete the user with the specified id from the 
database, etc.

  res.send({ message: 'User deleted' })
})

app.listen(3000, () => {

  console.log('Listening on port 3000')
})
Well that's impressive :)

But of course unless you had programming experience, you would have no way to structure this output correctly and actually take it live

I asked GPT how I could run it with this prompt:

Given this code for an example CRUD app, what unix commands could I run on my system to actually run this code?

$pasted_code_from_gp_comment

GPT's response:

> To run this code, you would need to install the express npm package by running npm install express in your terminal. After that, you can run the app by using the node command followed by the name of the file containing the code, for example: node app.js. This will start the server, which you can then access by going to http://localhost:3000/ in your web browser.

With follow up questions, such as "it says npm is not recognized command"; gpt will explain what that error means and how to fix it

This is the response to "it says npm is not recognized command":

> If you get an error that npm is not recognized as a command, it means that the npm command is not available on your system. This could be because you don't have Node.js installed, or because the npm command is not in your system path.

> To fix this error, you will need to install Node.js on your system. You can download and install the latest version of Node.js from the official website: https://nodejs.org/en/. After installing Node.js, you should be able to run the npm command from your terminal.

> Once you have installed Node.js, you can also check if the npm command is in your system path by running where npm on Windows or which npm on macOS or Linux. This should print the location of the npm command on your system. If it doesn't print anything, you may need to add the npm command to your system path manually.

> If you're still having trouble, you can try looking for solutions online or reaching out to the Node.js community for help. There are many forums and online communities where you can ask questions and get help from experienced users.

I’m impressed by its ability to correct itself.

Can’t wait to see what this technology looks like in a year.

Is it better than Copilot with comment-based incremental code writing?
Better really is too subjective and context dependent. Play with both and see what works for you. Copilot is GPT3 specifically trained on code, so my understanding is that it should be better... It's also fairly convenient due to the IDE plugins.