DEV Community

Discussion on: Build a RESTful API with the Serverless Framework

Collapse
 
mshaikhcci profile image
Mubina Shaikh • Edited

Hi, Sagar, i was trying to implement Nodejs App with Mysql to build it serverless following your article, i get this error.

Serverless: Configuration warning at 'provider.runtime': should be equal to one of the allowed values [dotnetcore2.1, dotnetcore3.1, go1.x, java11, java8, java8.al2, nodejs10.x, nodejs12.x, provided, provided.al2, python2.7, python3.6, python3.7, python3.8, ruby2.5, ruby2.7]

i use below versions
Angular:- 10.1.2
Node:- 12.18.0
Mysql:- 8.0.17

please help me with the above error, i have followed same steps as mentioned in your article. (excepts for db config password)

Collapse
 
sagar profile image
Sagar • Edited

basically, you need to provide runtime in the serverless.yml file.

# serverless.yml
service: pokemon-service

provider:
  name: aws
  runtime: nodejs12.x // <-- here provide runtime
  stage: dev
  region: us-east-1
  memorySize: 512
Collapse
 
mshaikhcci profile image
Mubina Shaikh

Hi Sagar,

Thank you for sharing, upon changing serverless.yml runtime to nodejs12.x, i am not getting the error i mentioned in previous comment.

I am attaching screenshots of calling API in postman i dont get response as shown in your article, and get pokemon by id API doesnt work at all.

Please let me knoew how to get data of API correctly.

Thread Thread
 
mshaikhcci profile image
Thread Thread
 
mshaikhcci profile image
Mubina Shaikh
Thread Thread
 
mshaikhcci profile image
Mubina Shaikh

Also, I tried to debug by putting console statements in index.js file API's but console statements are not printed in BE.

app.get('/pokemon/', (req, res) => {
const query = 'SELECT * FROM pokemon_tb'
pool.query(query, (err, results, fields) => {
if (err) {
const response = { data: null, message: err.message, }
console.log('***********', response);
res.send(response)
}

    const pokemons = [...results]
    const response = {
        data: pokemons,
        message: 'All pokemons successfully retrieved.',
    }
    res.send(response)
})

})

please tell me why ?

Thread Thread
 
sagar profile image
Sagar

IDK exact reason behind this. you need crosscheck function with the article mention code blocks and also you've to debug the root cause of this.

Thread Thread
 
mshaikhcci profile image
Mubina Shaikh

Hi, i had crossed checked function code blocks with article code blocks, its the same.
Can please tell me why console statements arent printing, it should print right ?