Create An App
Creating an app in Napnux is a straightforward process that allows you to build modular and maintainable components for your project. Let's walk through the process of creating an authentication app step by step.
Step 1: Project Setup​
- Open your project directory.
- Create a folder named
apps
. This directory will house all your individual apps. - Inside the
apps
folder, create a new folder namedauthApp
(for the authentication app).
Step 2: Set Up App Structure​
- Inside the
authApp
folder, create anindex.js
file. - Open the
index.js
file in your preferred code editor.
Step 3: Define Basic App Route​
//apps/authApp/index.js
const napnux = require("napnus");
module.exports = napnux().get("/", (req, res) => {
res.end("hello from authApp");
});
Step 4: Views Configuration​
- Create a folder named views inside the authApp folder.
- Modify the index.js file to include the views configuration:
//apps/authApp/index.js
const napnux = require("napnus");
module.exports = napnux()
.ejs({
views: __dirname + "/views", //new
})
.get("/", (req, res) => {
res.end("hello from authApp");
});
In this example we are using default ejs templating engine.
Step 5: Public Folder for Static Files​
- Create a folder named public inside the authApp folder.
- Place your static files (e.g., images, CSS, JavaScript) inside the public folder.
- Update the index.js file to serve static files:
//apps/authApp/index.js
const napnux = require("napnus");
module.exports = napnux()
.static(__dirname + "/public") //new
.ejs({
views: __dirname + "/views",
})
.get("/", (req, res) => {
res.end("hello from authApp");
});
Path for statics file for our app will be,
http://localhost:3000/authApp/public/images/dog.jpg
http://localhost:3000/authApp/public/css/style.css
http://localhost:3000/authApp/public/images/bg.png
http://localhost:3000/authApp/public/hello.html
http://localhost:3000/authApp/public/js/pikapika.js
Using Cli​
If you are useing Napnux-cli, you can use following command to generate an app.
nux create-app authApp
It will create an app inside your projects apps folder, easy!
Conclusion​
Congratulations! You've successfully created an authentication app using the Napnux framework. This app is now structured to handle routes, views, and static files in an organized and maintainable manner. You can further expand your app by adding authentication logic, views, and features as needed. With Napnux's modular approach, you can easily manage and extend your project by adding more apps for different functionalities.