A robust and adaptable template for building serverless applications and static sites with Netlify CLI. This project offers a modern setup with TypeScript, multiple serverless functions, and a customizable static frontend—perfect for blogs, APIs, or dynamic web apps! ✨
- Serverless Functions: Four TypeScript-based functions (
hello
,time
,echo
,neon
) with robust error handling and CORS support. 🛠️ - Static Site: A simple, customizable HTML frontend in the
public
directory, ready for frameworks like React or Vue. 🌐 - Netlify CLI Integration: Streamlined local development and deployment with
netlify dev
. ⚙️ - TypeScript Support: Type-safe functions using AWS Lambda types for reliability. 📝
- Yarn Workflow: Optimized package management with Yarn. 📦
- Modular Design: Easily extend with new functions, frontends, or integrations. 🔧
- Neon-Ready: Prepared for Neon Postgres integration with the
neon
function. 🗄️
netlify-cli-template/
├── netlify/
│ └── functions/
│ ├── hello.ts # Greets users with query params
│ ├── time.ts # Returns current server time
│ ├── echo.ts # Echoes POST request body
│ └── neon.ts # Placeholder for Neon Postgres integration
├── public/
│ └── index.html # Static site entry point
├── netlify.toml # Netlify configuration
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
- Node.js: Version 14 or higher. 🟢
- Yarn: Install with
npm install -g yarn
. 📦 - Netlify CLI: Install globally with
yarn global add netlify-cli
or locally viayarn add --dev netlify-cli
. 🌍 - Git: For version control and Netlify deployment. 📚
-
Clone the Repository:
git clone https://github.com/lizzyman04/netlify-cli-template.git cd netlify-cli-template
-
Install Dependencies:
yarn install
-
Link to Netlify:
yarn netlify init
Follow the prompts to connect to your Netlify site or create a new one.
-
Local Development:
yarn start
Starts a local server at
http://localhost:8888
. Functions are accessible athttp://localhost:8888/.netlify/functions/
. -
Test Functions:
- hello:
GET /api/hello?name=YourName
Example: ReturnsHello, YourName!
- time:
GET /api/time
Example: Returns current UTC time. - echo:
POST /api/echo
with JSON body
Example: Echoes back the payload. - neon:
GET /extensions/neon
Example: Placeholder for Neon integration.
Example
curl
forecho
:curl -X POST http://localhost:8888/api/echo -d '{"test": "Hello"}' -H "Content-Type: application/json"
Example
curl
forneon
:curl http://localhost:8888/extensions/neon
- hello:
-
Deploy to Netlify:
yarn deploy
Or push to GitHub for continuous deployment. 🚀
-
Type Checking:
yarn check-types
- Add Functions: Create new
.ts
files innetlify/functions/
. For custom folders (e.g.,netlify/extensions/
), configurenetlify.toml
or use a build script. 🛠️ - Frontend: Swap
public/
with frameworks like React, Vue.js, or Astro. 🌐 - Environment Variables: Add to
.env
or Netlify’s UI (e.g.,NETLIFY_TOKEN
,DATABASE_URL
for Neon). 🔑 - Build Process: Modify
yarn build
for static site generation. 🏗️ - Redirects: Update
netlify.toml
for custom routing rules. 🛤️
- hello: Greets users with a
name
query param (e.g.,/api/hello?name=Arlindo
). 👋 - time: Returns current UTC time in multiple formats (e.g.,
/api/time
). ⏰ - echo: Echoes POST request body (e.g.,
POST /api/echo
). 📢 - neon: Placeholder for Neon Postgres integration (e.g.,
GET /extensions/neon
). 🗄️
The neon
function is ready for Neon Postgres integration. To connect:
- Install the
pg
package:yarn add pg
. - Set
DATABASE_URL
in.env
or Netlify’s UI with your Neon connection string. - Update
neon.ts
with database logic (see commented example in the function). - Test queries locally and deploy. 🚀
- Fork the repository. 🍴
- Create a feature branch (
git checkout -b feature/your-feature
). 🌿 - Commit changes (
git commit -m 'Add your feature'
). 📝 - Push to the branch (
git push origin feature/your-feature
). 🚀 - Open a Pull Request. 🙌
MIT License. See LICENSE for details. 📄
- Arlindo Abdul
- GitHub: Lizzyman 🧑💻
Built with ❤️ using Netlify CLI and Yarn. Happy coding! 🎉