PhelipeLB / Crud-beer

App project to help taking order for a local beer store.
11 stars 1 forks source link

create a tiny nodejs server with koajs #7

Closed OtavioSC closed 1 year ago

OtavioSC commented 1 year ago

Using the koajs documentation, we could implement a simple node server like this:

//server.ts

import Koa from "koa";

const app = new Koa();

export default app.use(async ctx => {
  ctx.body = 'Hello World';
});

and a file to start the server:

  //index.ts

  import app from './server'

  dotenv.config()
  // change to env variable

  app.listen(process.env.PORT, async () => {
      console.log('Server is running')
  })

Each file in a src folder on server app directory

daniloab commented 1 year ago

nice