![]() To get started, create a folder named routes. Building RESTful APIs with the MERN stack Now, time to complete the route setup, and after that, we will see how to create RESTful APIs. Great! So far, we are on the right track, and our database is successfully connected. ![]() Now, you can run the project using the $ npm run app command. Then, paste the following code: // app.jsĪpp.get('/', (req, res) => res.send('Hello world!')) Īpp.listen(port, () => console.log(`Server running on port $`)) You can create this from the project folder with the $ touch app.js command (on macOS). Now, create a file named app.js for our entry point. This will define the start script of the application.Īfter that, your package.json should look like this: It is also important to define a start script here with "start": "node app.js". The app.js is the entry point for the application. Nodemon is a utility that will monitor for any changes in your source and automatically restart your server. To use nodemon, add "app": "nodemon app.js" to your scripts tag under the package.json file. If you don’t want to add this, you can skip it - it’s optional. Now, we’ll add nodemon as a dev dependency.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |