Minimal explanation, maximum focus on coding. Follow our step-by-step blog for a ready-to-deploy serverless API.

Serverless Node.js

Install Serverless globally:

npm install -g serverless

Create a new Serverless service:

serverless create --template aws-nodejs --path myService
cd myService

Install Express and Serverless HTTP:

npm init -y
npm install express serverless-http

Create a new file app.js:

const express = require('express');
const app = express();

app.get('/', function (req, res) {
  res.send('Hello World!');

module.exports = app;

Modify handler.js:

const serverless = require('serverless-http');
const app = require('./app.js');

module.exports.server = serverless(app);

Modify serverless.yml:

service: myService

  name: aws
  runtime: nodejs12.x

    handler: handler.server
      - http: ANY /
      - http: 'ANY {proxy+}'

Deploy your service:

serverless deploy

This will deploy your Express application as a Serverless service. You can now access your application via the endpoint provided by AWS.

Read more blogs

Categorized in: