#hello world
1 messages · Page 1 of 1 (latest)
To create a simple "Hello World" application using Next.js, you can use the create-next-app CLI tool. This tool allows you to quickly start building a new Next.js application with everything set up for you. You can create a new app using the default Next.js template, or by using one of the official Next.js examples.
Here are the steps to create a new project interactively:
- Run one of the following commands in your terminal:
npx create-next-app@latest
or
yarn create next-app
or
pnpm create next-app
or
bunx create-next-app
-
You will then be asked a series of prompts. Answer them according to your project requirements.
-
Once you've answered the prompts, a new project will be created with the correct configuration depending on your answers.
After creating the project, you can create a simple "Hello World" function. Here's an example of how you can do it:
async function greeting(){
console.log("Hello");
console.log("Goodbye");
}
To run the development server, use the following command:
npm run dev
Your site will now be running at http://localhost:8000.
Sources:
- Next.js > Docs > Pages > Api-reference > create-next-app (https://nextjs.org/docs/pages/api-reference/create-next-app)
- Github Issue (closed): [NEXT-517] Breakpoint not getting hit in VSCode with Next.js debugger config > Original post Part 2 (https://github.com/vercel/next.js/issues/45697)
- Templates > Next.js (https://vercel.com/templates/next.js/nextjs-boilerplate)
- Templates > Next.js > Quickstart > Open the code and start customizing (https://vercel.com/templates/next.js/medusa)
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@lucid pelican kapa.ai is still learning and improving, please let us know how it did by reacting below
@empty cape I need to ask you, is it possible to target global styles from a css module?
Let me check the knowledge base for you. One moment! :books:
Yes, it is possible to target global styles from a CSS module in Next.js. However, the way you handle global styles depends on whether you're working within the pages directory or the app directory.
In the pages directory, global stylesheets are restricted to only pages/_app.js. For example, you can import a global stylesheet named styles.css into your pages/_app.js file like this:
import '../styles.css'
export default function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
In the app directory, this restriction has been lifted. Global styles can be added to any layout, page, or component. For instance, you can import a global stylesheet named global.css into your app/layout.js file like this:
import './global.css'
export default function RootLayout({ children }) {
return (
<html lang="en">
<body>{children}</body>
</html>
)
}
It's important to note that due to the global nature of stylesheets, and to avoid conflicts, you may only import them inside pages/_app.js or app/layout.js.
Sources:
- Next.js > Docs > App > Building-your-application > Styling > CSS Modules > Global Styles (https://nextjs.org/docs/app/building-your-application/styling/css-modules#global-styles)
- Next.js > Docs > Pages > Building-your-application > Styling > CSS Modules > Global Styles (https://nextjs.org/docs/pages/building-your-application/styling/css-modules#global-styles)
- Next.js > Docs > App > Building-your-application > Upgrading > App Router Incremental Adoption Guide > Migrating from
pagestoapp> Step 7: Styling (https://nextjs.org/docs/app/building-your-application/upgrading/app-router-migration#step-7-styling) - Next.js > Docs > Pages > Building-your-application > Upgrading > From Pages to App > Migrating from
pagestoapp> Step 7: Styling (https://nextjs.org/docs/pages/building-your-application/upgrading/app-router-migration#step-7-styling)