Sabtu, 19 September 2020

Using Nodemon to Make Fast Refresh on Dynamic Routes and Express API in NextJS Project

The time when I create dynamic routes using route.js file in my NextJS project is very confusing. When I created or edited file in Express API, there are no automatic changes. I should typing "npm run dev" in my terminal cause it takes so much time to wait for the changes. 

So, I start to search on Google is there I can do with this, to make it faster if it cannot be automatic instead. Yup, there is NPM library called Nodemon. You still have to type some code to refresh the changes, but it is faster than just "npm run dev" do. 

Let's start to try how it is. 
  1. Let's install the library by typing "npm i nodemon" on the terminal. 
  2. After the nodemon successful installed, open the "package.json" and change dev script into "nodemon -w server.js" like on below. 
  3. Then, open your terminal and type "npm run build". 
  4. Wait for it, after finish then types "npm run build".
  5. Makes some changes on your Express API files. 
  6. Open the terminal again, type "rs" and press enter. 
  7. Voila... it's much faster than "npm run dev" to refresh or restart the server. 
Note:
  • I read some articles and found another way to solve this problem. You can use ts-node-dev but I'll try it later. Source: https://stackoverflow.com/questions/37979489/how-to-watch-and-reload-ts-node-when-typescript-files-change
Thank you for reading my blog post, see you in other articles. You can contact me if you wanna some help or make a collaboration.


Related Articles

0 komentar:

Posting Komentar