Too much wasted time π
Think about every time you started a new Express API. you start by creating a new folder, initialize npm, installing the essential dependencies one by one, creating the same folder structure with the same files with the same default code, and making a ton of config files for eslint, prettier, git, etc. All of that and you didn't even start writing any code for your project. setting up express project takes a lot of time upfront and it gets more frustrating if you are working with microservices as you will go by these same steps more and more. I tried to deal with this problem by creating a pre-configured project in a repository and clone it every time I wanted to create a new project, but I found myself still editing it every time to meet the requirements of the new project. I took some time doing this then I realize that this isn't an ideal solution. So, I decided to do what's called a programmer move and automate the process.π¨βπ»
the Solution π
To solve this problem, I started to work on a package called new-express-app to create ready to code express apps with simple cli command. the package has to be different from the repository solution as it should create the project with my exact needs no more no less. So, I used the Inquirer.js package to ask the user a series of questions about his needs. and here is the questions:
Enter Project Name:
Enter version:
Enter description:
Enter author name:
Want to initialize git?
Want to install dotEnv?
Want to install database driver?
Want to initialize eslint/prettier?
the first 4 questions to create the package.json
file and the rest to determine which dependencies/devdependencies to install. the package installs some dependencies by default which are:
and you can optionally add these dependencies:
the package uses the child process exec
to initialize git, install dependencies and even open vscode for you. also it adds all the config files for eslint, prettier, dotenv and git. and the required code for database connection is also added so you only need to add your connection string and start coding immediately π. you can refer to the GitHub repository to see the created folder structure and the files content.
let's some up π
- Install new-express-app globally.
npm i -g new-express-app
- Answer the questions
- You are ready to change the world.πͺ
Hope you like it and if you have any ideas to improve please, leave it in the comments π .
Have time to help? π€
If you like the idea and you have the time to help feel free to go to the GitHub repository and add the functionality that you want.
Top comments (28)
I feel like Express is a framework for writing web frameworks. It is so low-level and every method becomes so repetitive, that unless you or your company have a solid library built on top of it already, it is one of the most unproductive solutions for a server.
For really simple CRUD apps, I think it would be cool to see a database schema transformed into a REST API. Not applicable most of the time, but totally automated when required.
I'm pretty new to node.js with less that a full year of experience. and we I get started I found express is the most used library with node.js when it comes to building REST API's. so I started using it and I did't expose to any other alternative. and I guess Google Firebase implements the idea that you are taking about, but it has a lot of limitations. I see it with express like you trade the simplicity for the more functionalities you get over something like FireBase.
I think there are some solutions that do just that if you look around, you can also try json-server for really simple apps
Yea, there are more complete frameworks like eggjs and nest.
Hasura.io does almost that. Creates a graphql API from your postgres schema.
Thanks for the article. This is motivating me to look at yeoman again and make a template. You are correct, so much repeated time wasting work to start a new project.
Yup, it seems like 5 or 10 mins but in really it becomes too much when the number of projects increases. I didn't know about yeoman before but it seems like a pretty good tool and it would've been saved a lot of time with me, but it was fun coding it from scratch π
In the end, the fun is what really matters :high-five:
There is already a framework for that. You can check out Expresswebjs github.com/Alexigbokwe/ExpressWebJs
I took a look on the repo and I see a great work and effort with pretty good ideas β€οΈ. And I see that you are the author so if you don't mind we can work together to build a better library to server this purposeπ
+1 contributor, if you guys are willing to team up! I have also done something like this
I'm ready whenever you are ready π€
Count me in..
Don't go through my repo π
That will be nice, we are happy to release the new version of Expresswebjs. You can check out the website at expresswebjs.com for documentation and use.
I could be wrong, but I don't think cors module is needed by default, I think the setup you have for cors is what express already does by default, the cors module is only needed if you need to make exceptions.
When I started using expess i spent a whole day trying to receive requests from the browser with react js. I was sending requests to the backend with postman and it works fine but it doesn't receive and requests from the browser. And then I found that to be able to receive browser requests you have to use the cors module. So I thought it would be convenient to add it by default as most of express API's will be consumed by some sort of a frontend which may work on a browser π
It depends on if the server is hosting the page or not. But yeah I see what you mean, makes sense! Really cool project π€
Really helpful. Its a crazy orchestra with setp these days.
Great effort !!!
Thanks π.
no i code web in c++
Coding isn't limited to one language and this is one of the reasons why I love coding so much. Pick the language that you want and do whatever you want. Maybe some languages are better in sertin fields, but you know it's doable with any language if you want. Personally, I chose JavaScript because, the same idea of having a language that works everywhere and JavaScript has a solid fremeworks/libraries on every feild. This isn't making it the best solution, but if you are like me working frontend, backend and even mobile development I guess having a one language to do all of them is a great thing to have π
yes sir i got you i just joking no way i use c++ as backend also
It sounds like a lot of fun to build such a tool. Personally, I will just stick with Adonis though, it comes with most things you need for your average app.
Sadly, I didn't try it till now, but surely I'll give it a try soon. thanks π
thanks, it's now updated! π
Now in V 1.2.0 you can create Typescript project with TsLint and Prettier configuration π