From my perspective, the JAMstack is specially appealing to developers with a frontend background. We can now deploy backend services without needing a deep understanding of server-side architecture, scalability, or even caching.
With that in mind, I have started a new project create-netlify-ts
. My point with this project is leverage the self-documenting aspect of TypeScript to lower the barrier for Lambda-Functions even more.
How β
Well, by using the self-documenting aspect of TypeScript. On strongly typed code (and luckily with an IDE properly configured), your methods will whisper to you what they need.
But, adding TypeScript to a NodeJS adds a new layer of complexity. Node doesn't get types, so the simplicity of writin a .js
file and pushing so it's β¨magicallyβ¨ live on Netlify goes away.
In comes netlify-lambda
to add a build step to your Netlify Function. I wrote a small tutorial on getting this running.
Deploy Netlify Functions with TypeScript
Atila Fassina γ» Aug 10 '20
But even if you know this setup inside-out and backwards, it is a bit annoying to make it every.single.time.
I know that feeling. So I made something.
Faster than instant noodles π₯‘
With a simple command in your terminal:
# if you use Yarn
yarn create netlify-ts
# if you use NPM
npx create-netlify-ts
A new project is bootstrapped for you, ready to be deployed on Netlify Functions with another simple command.
The boilerplate is a bit more than the minimum requirements for a working Netlify Function. It can give you some opinionated coding style (very little), and also brings the request
and response
types, so you can easily write the logic of your service without ever alt-tabbing
away from the IDE.
atilafassina / create-netlify-ts
π Building Netlify Functions with TypeScript has never been this easy
create-netlify-ts
π Building Netlify Functions with TypeScript easily
π¦ Package Manager agnostic
πΎ No production footprint
π Ready to deploy
β―_
npm
npx create-netlify-ts
yarn
yarn create netlify-ts
β Answer the questions and start coding!
π² File tree
{{ package-name }}
βββ src
β βββ {{ your-function-name }}.ts
βββ package.json
βββ .babelrc
βββ .gitignore
βββ netlify.toml
𧳠Installed dependencies
All depdendencies are installed as devDependencies
, create-netlify-ts has no footprint on your production code.
Required dependencies
Package Name
Why
netlify-lambda
Adds build-step to Netlify Functions
typescript
The compiler for TypeScript (
tsc
)
@babel/preset-env
Tells Babel which JavaScript syntax to output
@babel/preset-typescript
Teach Babel to use TypeScript compiler
@types/aws-lambda
Request/Response types for AWS Lambdasβ
β : Netlify Functions runs on top of AWS-Lambdas
Optional dependencies
- Netlify CLI To run Netlify Functions locally
- Prettier: with some opinionated configuration
π« Flying solo
Itβs a dangerous road out there. Take these:
πΉ Writeβ¦
Features β¨
- Server
Rewrite
to the root of your domain - Deploy setup
- Optional dependencies to streamline your workflow
Requirements βοΈ
There are 2 things which I have not been able to workaround if it is the first time deploying to Netlify for you.
You need to:
- Manually create your Netlify account beforehand
- If using Netlify CLI you need to link your account with the CLI manually as well
Help wanted π
Create-Netlify-TS is on a very early stage, and I welcome any kind of contribution. For example, you can:
- offer feedback on your usage
- suggest improvements on existing features and configuration
- add more testing coverage
- automate some needed tasks (package publishing for example)
- anything else you can think of, pop an issue and let's talk!
π
If you found this project useful, please consider sharing it with your network, that would help me a lot to continue and make improvements. π
Top comments (4)
Why hasn't it been upgraded?
Netlify supports it out-of-the-box now.
this is actually great - saved my time for boilerplate
I have got a problem - tried spinning up local server with netlify dev and netlify lamda serve. In both of them, I am not able to run the compiled functions. Can you tell what am I missing?