简体   繁体   中英

JavaScript project structure

I'm pretty new to JavaScript and I want to create a project. I've read online that by using npm init a package.json file is created. By using npm install --save or npm install --save--dev I can install packages and they will be added to that package.json file.

  • I used npm install jquery --save to be able to use jQuery. But how can I include jQuery into my JavaScript file?

  • When I have a project folder with a src-folder and html-folder. Do I have to put the package.json file in the src-folder or in the project folder?

  • Are there any other conventions I should know about?

Yes you can but I suggest for you to see http://yeoman.io

A little "architect" who can to help you to start your studies about projects structures.

http://yeoman.io/generators/

I created a project for you that has Node.js, Express and jQuery all set up:

https://github.com/timothyerwin/node-express-jquery-boiler

You should be able to start it with:

npm install
npm start
http://localhost:3000

The problem is that nodejs is only used to make custom builds of jquery , more info here:

How to build your own jquery (Github)

You dont need to put any json file in your proyect, you can learn how to build Jquery in a different directory here:

Building to a different directory (Github)

Note: Jquery is a client-side library not a sever side module.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM