With this tool you can initialize your node projects more easy
This tool is writted in bash, because it, it only works in linux
To install first clone the repository
mkdir -p ./repo
cd repo
git clone https://github.com/AlphaTechnolog/node-init node-init
cd node-initThen run the installer:
sudo ./install.shOr with make:
sudo make installTo uninstall the program you can run the uninstall script:
sudo ./uninstall.shOr with make:
sudo make uninstallThe name of the program binary is ni, you can create a new project with npm
named sample-project with node-init (called ni between now):
ni sample-projectIt command create a new folder in your pwd named sample-project and then it run:
npm init -yLike the output of the command explain:
+----------------------------------------------------------------------+ [5/5]
| Welcome to node-init |
| |
| > With me you can init more easy your node projects with npm or yarn |
+----------------------------------------------------------------------+
[*] Creating project (sample-project)
$ mkdir -p sample-project
$ cd sample-project
$ npm init -y
Wrote to /home/user/sample-project/package.json:
{
"name": "sample-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
$ cd ..
[+] Done
[+] Created the project successfully, execute: $ cd ./sample-project to start using your new node projectThen if you run this:
cd sample-project
lsYou will get a list of file in the sample-project folder, it's the package.json
created with npm
Node init also support yarn, it support npm and yarn, you can create a new project with yarn, with a command like this:
ni sample-project yarnWhere the second argument of the command is the dependency manager, like in the help of ni (
ni --help), it only acceptnpmoryarn
It command create a new folder named sample-project and then execute in it folder, the next command:
yarn init -yLike the explanation in the node-init output:
+----------------------------------------------------------------------+
| Welcome to node-init |
| |
| > With me you can init more easy your node projects with npm or yarn |
+----------------------------------------------------------------------+
[*] Creating project (sample-project)
$ mkdir -p sample-project
$ cd sample-project
$ yarn init -y
yarn init v1.22.17
warning The yes flag has been set. This will automatically answer yes to all questions, which may have security implications.
success Saved package.json
Done in 0.05s.
$ cd ..
[+] Done
[+] Created the project successfully, execute: $ cd ./sample-project to start using your new node project
If you run this command:
cd sample-project
lsYou will get the package.json file created by yarn
You can create a project with yarn or npm with dependencies.
To create a project with npm and some dependencies like uuid, you can run
a command like this:
ni sample-project npm uuidAnd then it create a new folder named sample-project, then it run
npm init -y and then npm install uuid, like in the explanation in
the node-init output:
+----------------------------------------------------------------------+
| Welcome to node-init |
| |
| > With me you can init more easy your node projects with npm or yarn |
+----------------------------------------------------------------------+
[*] Creating project (sample-project)
$ mkdir -p sample-project
$ cd sample-project $ npm init -y
Wrote to /home/user/sample-project/package.json:
{
"name": "sample-project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
$ cd ..
[+] Done
[*] Installing dependencies: uuid
$ cd sample-project
$ npm install uuid
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN sample-project@1.0.0 No description
npm WARN sample-project@1.0.0 No repository field.
+ uuid@8.3.2
added 1 package in 0.35s
$ cd ..
[+] Done
[+] Created the project successfully, execute: $ cd ./sample-project to start using your new node project
Then, if you run:
cd sample-project && lsYou can get a list of the files, like this:
drwxr-xr-x - user user 28 Dec 12:39 node_modules
.rw-r--r-- 355 user user 28 Dec 12:39 package-lock.json
.rw-r--r-- 274 user user 28 Dec 12:39 package.jsonAnd if you want to create a project named sample-project with yarn and install dependencies
like express and morgan, you can run the next command:
ni sample-project yarn express,morganAnd then the project will be created like this:
mkdir -p ./sample-project
cd sample-project
yarn init -y
yarn add express morganIt commands will be executed by
node-init
To create a new project with typescript you will need the next dependencies:
- express: For make the server
- morgan: To log the requests
Dev dependencies:
- typescript: To type javascript
- @types/node: The types of the node variables
- @types/express: The types for express
- @types/morgan: The types for morgan
- nodemon: For hot reloading server
The typically way to create a project with this features is:
mkdir -p ./express-ts-project
cd express-ts-project
yarn init -y
yarn add express morgan
yarn add -D @types/node @types/morgan @types/express nodemon typescriptOr with npm
mkdir -p ./express-ts-project
cd express-ts-project
npm init -y
npm install express morgan
npm install -D @types/node @types/morgan @types/express nodemon typescriptBut you can create it with only one command with this tool, like this:
With yarn:
ni express-ts-project yarn express,morgan @types/node,@types/morgan,@types/express,nodemon,typescriptWith npm
ni express-ts-project npm express,morgan @types/node,@types/morgan,@types/express,nodemon,typescriptAnd its commands will create the project successfully
Thank you for read me, and thank you for use node-init, if you like this
project, please give me a star :)