I have an ExpressJS application. I want to execute it on Lambda functions and EC2.
In order to execute it on Lambda functions, I use the @vendia/serverless-express
package.
In order to execute it on EC2, I want to exclude the installation of @vendia/serverless-express
.
The env variable TYPE
makes it possible to distinguish between the two deployments.
Since, @vendia/serverless-express
is part of my dependencies
in package.json
it gets installed on EC2 as well. Is there a way to exclude it using the TYPE
environment variable for EC2 deployment?
CodePudding user response:
You can define a block in your package.json such as:
{
...
"serverlessDependencies":
{
"@vendia/serverless-express": "*"
},
...
}
And then, use a library called handpick to select when to install them.
Then write a bash script that will evaluate NODE_ENV
and decide what to do:
pseudo code:
npm install
if(NODE_ENV == 'serverless')
npx handpick --target=serverlessDependencies