Next.js Codebase Analysis <> create-next-app <> index.ts explained — Part 1.10
In the previous article, I wrote about project name validation. In this article, let’s look at more code from index.ts
if (program.example === true) {
console.error(
'Please provide an example name or url, otherwise remove the example option.'
)
process.exit(1)
}
program.example reminds of accessing options passed in via the cli
example is an option as shown below:
// https://www.npmjs.com/package/commander#options
// -e
// https://github.com/vercel/next.js/tree/canary/packages/create-next-app#non-interactive
.option(
'-e, --example [name]|[github-url]',
`
An example to bootstrap the app with. You can use an example name
from the official Next.js repo or a GitHub URL. The URL can use
any branch and/or subdirectory
`
)
Pass it as npx create-my-app -e, because it needs url when there is no url provided, the following error is thrown
Conclusion:
As I look at the more lines of code, I see that there is safeguarding in place for options submitted, for example, for project name and now for example.
Take the user input and importantly validate it before proceeding further.
If you have any questions, feel free to reach out to me at ramu.narasinga@gmail.com

Get free courses inspired by the best practices used in open source.
About me:
Hey, my name is Ramu Narasinga. I study large open-source projects and create content about their codebase architecture and best practices, sharing it through articles, videos.
I am open to work on interesting projects. Send me an email at ramu.narasinga@gmail.com
My Github — https://github.com/ramu-narasinga
My website — https://ramunarasinga.com
My Youtube channel — https://www.youtube.com/@ramu-narasinga
Learning platform — https://thinkthroo.com
Codebase Architecture — https://app.thinkthroo.com/architecture
Best practices — https://app.thinkthroo.com/best-practices
Production-grade projects — https://app.thinkthroo.com/production-grade-projects