Learn how to customize templates to fit your specific needs
Templates provided by create-awesome-node-app are designed to be customizable. This guide will show you how to modify templates to suit your specific requirements, from simple configuration changes to more advanced customizations.
After creating a project with create-awesome-node-app, you can modify its structure to better suit your needs. Here are some common customizations:
You can reorganize the components directory structure to better match your project's architecture.
Create additional directories for features, contexts, hooks, or other code organization patterns.
Adjust the app directory structure to implement your desired routing and page organization.
Add or modify files in the public directory to include your own static assets.
Templates come with default configurations that you can modify to match your requirements:
{ "compilerOptions": { "target": "ES2020", "useDefineForClassFields": true, "lib": ["ES2020", "DOM", "DOM.Iterable"], "module": "ESNext", "skipLibCheck": true, /* Bundler mode */ "moduleResolution": "bundler", "allowImportingTsExtensions": true, "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", /* Linting */ "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "noFallthroughCasesInSwitch": true, /* Paths */ "baseUrl": ".", "paths": { "@/*": ["./src/*"] } }, "include": ["src"], "references": [{ "path": "./tsconfig.node.json" }] }
You can customize the TypeScript configuration to adjust compiler options, add path aliases, or change included files.
You can add, remove, or update dependencies to tailor the project to your needs:
# Add a new dependency npm install axios # Add a development dependency npm install --save-dev jest @testing-library/react # Update a dependency npm update react # Remove a dependency npm uninstall unused-package
After modifying dependencies, you may need to update your project's configuration files to properly integrate the new packages.
If you want to add extensions to an existing project created with create-awesome-node-app, you have a few options:
Different templates have specific customization options. Here are some examples:
The React Vite template provides several customization options:
src/App.tsx
or create a dedicated router configuration.// Example of customizing React Router in App.tsx import { BrowserRouter, Routes, Route } from 'react-router-dom' import Home from './pages/Home' import About from './pages/About' import Contact from './pages/Contact' import NotFound from './pages/NotFound' function App() { return ( <BrowserRouter> <Routes> <Route path="/" element={<Home />} /> <Route path="/about" element={<About />} /> <Route path="/contact" element={<Contact />} /> <Route path="*" element={<NotFound />} /> </Routes> </BrowserRouter> ) }
For more advanced customization needs, you can modify the core functionality of the template:
You can customize the build process by modifying the build configuration files:
vite.config.ts
to customize the build process.next.config.js
to adjust Next.js behavior.nest-cli.json
and tsconfig.build.json
for build customization.// Example of customizing Next.js config /** @type {import('next').NextConfig} */ const nextConfig = { images: { domains: ['example.com', 'cdn.example.com'], }, experimental: { serverActions: true, }, async redirects() { return [ { source: '/old-page', destination: '/new-page', permanent: true, }, ] }, } module.exports = nextConfig
For templates that use Webpack, you can customize the Webpack configuration:
// Example of customizing Next.js Webpack config /** @type {import('next').NextConfig} */ const nextConfig = { webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => { // Add a custom webpack plugin config.plugins.push(new webpack.IgnorePlugin({ resourceRegExp: /^./locale$/, contextRegExp: /moment$/, })) // Add a custom loader config.module.rules.push({ test: /.svg$/, use: ['@svgr/webpack'], }) return config }, } module.exports = nextConfig
Customize your application's behavior using environment variables:
# .env file example API_URL=https://api.example.com DEBUG=true NODE_ENV=development # For client-side variables in Next.js NEXT_PUBLIC_SITE_URL=https://example.com
Access environment variables in your code:
// In Node.js (server-side) const apiUrl = process.env.API_URL // In React (client-side) // Note: In Vite, use import.meta.env instead of process.env const siteUrl = import.meta.env.VITE_SITE_URL // In Next.js (client-side) const siteUrl = process.env.NEXT_PUBLIC_SITE_URL