28
Let’s build and deploy a Full Stack Next.js App: Part 1
Next.js is referred to as the React framework for production, which comes with more features than simple React as a library. It gives us rules and guidelines on how we should structure our projects and it improves React developers' life, with built-in features like file-system based routing or “head” metadata for SEO.
In this article, we will build a simple food app that displays menu. It will be styled with Tailwind Css in the first part, and in the coming parts, we will connect the app to a MongoDB database and deploy it on Vercel.
For the tutorial to go well, you must have basic knowledge of Node js and React and have either a GitHub / Bitbucket / Gitlab account. You need also to have at least Node js 14.18.1 LTS and Git installed on your computers.
All the prerequisites are met, open your terminal and create a new project;
$ mkdir next-food-app
$ cd next-food-app
$ npm init -y
$ npm install react react-dom
$ npm install next
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start"
},
Note: Next.js comes with the file-system based routing feature, which makes all files added to the “/pages” directory available as routes. All files except “index.js”, which the Router automatically routes to the root of the directory.
/pages/index.js
=> /
/pages/meals/index.js
=> /meals
/pages/meals.js
=> /meals
const HomePage = () => {
return <h1>Welcome to our Food Next.js App 😊</h1>;
};
export default HomePage;
$ npm run dev

You will get the same page on your browser if nothing was omitted.
$ npm install tailwindcss postcss autoprefixer
$ npx tailwindcss init -p
module.exports = {
purge: ["./pages/**/*.{js,ts,jsx,tsx}", "./components/**/*.{js,ts,jsx,tsx}"],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
};
@tailwind base;
@tailwind components;
@tailwind utilities;
Note: In Next.js the file "_app.js" in the "/pages" directory overrides the default “App” component that allows us to add global css to the whole application.
import "../public/style/global.css";
const MyApp = ({ Component, pageProps }) => {
return <Component {...pageProps} />;
};
export default MyApp;
Put the code above in your "_app.js" file, run
If the procedure was followed correctly, you will notice a difference with the text font between the project before and after tailwind css. Just like in the images below;
$ npm run dev
and open your browser on http://localhost:3000 .If the procedure was followed correctly, you will notice a difference with the text font between the project before and after tailwind css. Just like in the images below;
Note: Next.js is built on top on react, therefore react components are part of it.
const MealItem = () => {
return (
<div className="w-1/4 p-8 shadow-lg rounded-lg bg-yellow-50">
<img src="/img/meal1.PNG" className="w-auto h-auto" alt="Chicken Salad" />
<div className="text-center py-2">
<h3 className="text-xl font-normal">
Chicken Salad
<span className="px-3 font-light text-yellow-500">(4 dishes)</span>
</h3>
<p className="text-gray-500 text-base">Herico de Porto</p>
<button className="bg-yellow-500 px-4 py-2 rounded-lg text-gray-50 font-medium mt-2">
Details
</button>
</div>
</div>
);
};
export default MealItem;
import MealItem from "./MealItem";
const MealList = () => {
return (
<div className="flex flex-wrap">
<MealItem />
</div>
);
};
export default MealList;
import MealList from "../components/MealList";
const HomePage = () => {
return <MealList />;
};
export default HomePage;
Download the image found on this link -> https://github.com/musole-masu/nextjs-food-app/blob/main/public/img/meal1.PNG
Create in the "/public" directory a folder named "/img" and put the downloaded image in there.
Now, wrap your pages with the style added in the "_app.js" just like it's done below:
import "../public/style/global.css";
const MyApp = ({ Component, pageProps }) => {
return (
<div className="max-w-7xl mx-auto py-40">
<Component {...pageProps} />
</div>
);
};
export default MyApp;
$ npm run dev
, then go to http://localhost:300

If you have this exact page on the browser, it means that you have completed each step of this tutorial correctly. Congrats :)
The Part 1 of our tutorial ends here. To summarize, it was focused on the project creation, with the installation of dependencies and also focused on styling.
Part 2 will be published very soon, so stay tuned and follow me on Twitter for updates.
Part 2 will be published very soon, so stay tuned and follow me on Twitter for updates.
Find the completed project here.
28