Generate NODE JS web application - Express generator module
Auto generate NODE JS web application folder structure.
This article is for beginners who wants to create a web
application using NODE JS but don’t know about the project structure and basic
files inside the folders. You can create
a folder Skelton using Express generator
module.
It’s very simple to generate web application using
express-generator. Before auto generate project structure, you need to ensure
that NODE JS is properly installed in you PC. Must read https://java.gunustories.com/2018/06/create-first-node-js-application.html
article to ensure that NODE JS framework is installed in your PC.
You just need to
follow below instruction to generate it.
1) Create a folder NodeJSExamples in your C:\ drive.
2) OPEN Command prompt and run cd NodeJSExamples command.
3) run $ npm install express-generator -g command to install
express generator
4) run $ express --view=hbs mywebapp command. This command will
generate the folder structure inside the mywebapp folder.
Below output
will be generated
C:\NodeJSExamples>express
--view=hbs mywebapp
create : mywebapp\
create : mywebapp\public\
create : mywebapp\public\javascripts\
create : mywebapp\public\images\
create : mywebapp\public\stylesheets\
create :
mywebapp\public\stylesheets\style.css
create : mywebapp\routes\
create : mywebapp\routes\index.js
create : mywebapp\routes\users.js
create : mywebapp\views\
create : mywebapp\views\error.hbs
create : mywebapp\views\index.hbs
create : mywebapp\views\layout.hbs
create : mywebapp\app.js
create : mywebapp\package.json
create : mywebapp\bin\
create : mywebapp\bin\www
change directory:
> cd mywebapp
install dependencies:
> npm install
run the app:
> SET DEBUG=mywebapp:* & npm start
C:\NodeJSExamples>
5) Now go to the mywebapp folder using cd mywebapp command and install dependency as below
C:\NodeJSExamples>cd
mywebapp
C:\NodeJSExamples\mywebapp>npm
install
npm notice
created a lockfile as package-lock.json. You should commit this file.
added 81
packages in 2.489s
6) Run your first web app using npm start command.
7) Once your application will have ran successfully.
J
Now you have learn how to create web application in NODE JS using express
generator.
Comments
Post a Comment